[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 9 | #include <stdint.h> |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11 | #include <limits> |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 12 | #include <set> |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 13 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14 | #include <utility> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 15 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 16 | |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 17 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 18 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 19 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 20 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 21 | #include "base/logging.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 22 | #include "base/macros.h" |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 23 | #include "base/memory/ptr_util.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 24 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 25 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 26 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 27 | #include "base/strings/utf_string_conversions.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 28 | #include "base/test/scoped_task_environment.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 29 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 30 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 31 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 32 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 33 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 34 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 35 | #include "net/base/load_timing_info.h" |
| 36 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 37 | #include "net/base/net_errors.h" |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 38 | #include "net/base/network_throttle_manager.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 39 | #include "net/base/proxy_delegate.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 40 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 41 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 42 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 43 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 44 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 45 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 46 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 47 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 48 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 49 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 50 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 51 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 52 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 53 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 54 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 55 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 56 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 57 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 58 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 59 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 60 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 61 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 62 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 63 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 64 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 65 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 66 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 67 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 68 | #include "net/log/test_net_log_entry.h" |
| 69 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 70 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 71 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 72 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 73 | #include "net/proxy/proxy_resolver.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 74 | #include "net/proxy/proxy_server.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 75 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 76 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 77 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 78 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 79 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 80 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 81 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 82 | #include "net/socket/socket_test_util.h" |
| 83 | #include "net/socket/ssl_client_socket.h" |
bnc | 8f8f7d30 | 2017-04-24 18:08:06 | [diff] [blame] | 84 | #include "net/spdy/chromium/spdy_session.h" |
| 85 | #include "net/spdy/chromium/spdy_session_pool.h" |
| 86 | #include "net/spdy/chromium/spdy_test_util_common.h" |
| 87 | #include "net/spdy/core/spdy_framer.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 88 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 89 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 90 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 91 | #include "net/ssl/ssl_config_service_defaults.h" |
| 92 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 93 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 94 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 95 | #include "net/test/gtest_util.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 96 | #include "net/test/net_test_suite.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 97 | #include "net/test/test_data_directory.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 98 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 99 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 100 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 101 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 102 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 103 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 104 | using net::test::IsError; |
| 105 | using net::test::IsOk; |
| 106 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 107 | using base::ASCIIToUTF16; |
| 108 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 109 | //----------------------------------------------------------------------------- |
| 110 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 111 | namespace net { |
| 112 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 113 | namespace { |
| 114 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 115 | class TestNetworkStreamThrottler : public NetworkThrottleManager { |
| 116 | public: |
| 117 | TestNetworkStreamThrottler() |
| 118 | : throttle_new_requests_(false), |
| 119 | num_set_priority_calls_(0), |
| 120 | last_priority_set_(IDLE) {} |
| 121 | |
| 122 | ~TestNetworkStreamThrottler() override { |
| 123 | EXPECT_TRUE(outstanding_throttles_.empty()); |
| 124 | } |
| 125 | |
| 126 | // NetworkThrottleManager |
| 127 | std::unique_ptr<Throttle> CreateThrottle(ThrottleDelegate* delegate, |
| 128 | RequestPriority priority, |
| 129 | bool ignore_limits) override { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 130 | auto test_throttle = |
| 131 | base::MakeUnique<TestThrottle>(throttle_new_requests_, delegate, this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 132 | outstanding_throttles_.insert(test_throttle.get()); |
| 133 | return std::move(test_throttle); |
| 134 | } |
| 135 | |
| 136 | void UnthrottleAllRequests() { |
| 137 | std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
vmpstr | 6d9996c8 | 2017-02-23 00:43:25 | [diff] [blame] | 138 | for (auto* throttle : outstanding_throttles_copy) { |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 139 | if (throttle->IsBlocked()) |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 140 | throttle->Unthrottle(); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | void set_throttle_new_requests(bool throttle_new_requests) { |
| 145 | throttle_new_requests_ = throttle_new_requests; |
| 146 | } |
| 147 | |
| 148 | // Includes both throttled and unthrottled throttles. |
| 149 | size_t num_outstanding_requests() const { |
| 150 | return outstanding_throttles_.size(); |
| 151 | } |
| 152 | |
| 153 | int num_set_priority_calls() const { return num_set_priority_calls_; } |
| 154 | RequestPriority last_priority_set() const { return last_priority_set_; } |
| 155 | void set_priority_change_closure( |
| 156 | const base::Closure& priority_change_closure) { |
| 157 | priority_change_closure_ = priority_change_closure; |
| 158 | } |
| 159 | |
| 160 | private: |
| 161 | class TestThrottle : public NetworkThrottleManager::Throttle { |
| 162 | public: |
| 163 | ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
| 164 | |
| 165 | // Throttle |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 166 | bool IsBlocked() const override { return throttled_; } |
| 167 | RequestPriority Priority() const override { |
| 168 | NOTREACHED(); |
| 169 | return IDLE; |
| 170 | } |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 171 | void SetPriority(RequestPriority priority) override { |
| 172 | throttler_->SetPriorityCalled(priority); |
| 173 | } |
| 174 | |
| 175 | TestThrottle(bool throttled, |
| 176 | ThrottleDelegate* delegate, |
| 177 | TestNetworkStreamThrottler* throttler) |
| 178 | : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 179 | |
| 180 | void Unthrottle() { |
| 181 | EXPECT_TRUE(throttled_); |
| 182 | |
| 183 | throttled_ = false; |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 184 | delegate_->OnThrottleUnblocked(this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | bool throttled_; |
| 188 | ThrottleDelegate* delegate_; |
| 189 | TestNetworkStreamThrottler* throttler_; |
| 190 | }; |
| 191 | |
| 192 | void OnThrottleDestroyed(TestThrottle* throttle) { |
| 193 | EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 194 | outstanding_throttles_.erase(throttle); |
| 195 | } |
| 196 | |
| 197 | void SetPriorityCalled(RequestPriority priority) { |
| 198 | ++num_set_priority_calls_; |
| 199 | last_priority_set_ = priority; |
| 200 | if (!priority_change_closure_.is_null()) |
| 201 | priority_change_closure_.Run(); |
| 202 | } |
| 203 | |
| 204 | // Includes both throttled and unthrottled throttles. |
| 205 | std::set<TestThrottle*> outstanding_throttles_; |
| 206 | bool throttle_new_requests_; |
| 207 | int num_set_priority_calls_; |
| 208 | RequestPriority last_priority_set_; |
| 209 | base::Closure priority_change_closure_; |
| 210 | |
| 211 | DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler); |
| 212 | }; |
| 213 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 214 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 215 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 216 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 217 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 218 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 219 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 220 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 221 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 222 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 223 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 224 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 225 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 226 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 227 | const char kAlternativeServiceHttpHeader[] = |
| 228 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 229 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 230 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 231 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 232 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 233 | } |
| 234 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 235 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 236 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 237 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 238 | } |
| 239 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 240 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 241 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 242 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 243 | } |
| 244 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 245 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 246 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 247 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 248 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 249 | if (!params) |
| 250 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 251 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 252 | if (!params->GetList("headers", &header_list)) |
| 253 | return false; |
| 254 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 255 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 256 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 257 | return true; |
| 258 | } |
| 259 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 260 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 261 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 262 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 263 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 264 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 265 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 266 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 267 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 268 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 269 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 270 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 271 | |
| 272 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 273 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 274 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 275 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 276 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 277 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 278 | } |
| 279 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 280 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 281 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 282 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 283 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 284 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 285 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 286 | |
| 287 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 288 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 289 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 290 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 291 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 292 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 293 | load_timing_info.send_start); |
| 294 | |
| 295 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 296 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 297 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 298 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 299 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 300 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 304 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 305 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 306 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 307 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 308 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 309 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 310 | |
| 311 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 312 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 313 | load_timing_info.proxy_resolve_end); |
| 314 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 315 | load_timing_info.send_start); |
| 316 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 317 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 318 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 319 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 320 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 321 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 325 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 326 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 327 | int connect_timing_flags) { |
| 328 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 329 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 330 | |
| 331 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 332 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 333 | load_timing_info.proxy_resolve_end); |
| 334 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 335 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 336 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 337 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 338 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 339 | load_timing_info.send_start); |
| 340 | |
| 341 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 342 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 343 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 344 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 345 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 346 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 347 | } |
| 348 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 349 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 350 | headers->SetHeader("Connection", "Upgrade"); |
| 351 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 352 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 353 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 354 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 355 | } |
| 356 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 357 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 358 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 359 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 360 | } |
| 361 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 362 | // Note that the pointer written into |*throttler| will only be valid |
| 363 | // for the lifetime of the returned HttpNetworkSession. |
| 364 | std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler( |
| 365 | SpdySessionDependencies* session_deps, |
| 366 | TestNetworkStreamThrottler** throttler) { |
| 367 | std::unique_ptr<HttpNetworkSession> session( |
| 368 | SpdySessionDependencies::SpdyCreateSession(session_deps)); |
| 369 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 370 | auto owned_throttler = base::MakeUnique<TestNetworkStreamThrottler>(); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 371 | *throttler = owned_throttler.get(); |
| 372 | |
| 373 | HttpNetworkSessionPeer peer(session.get()); |
| 374 | peer.SetNetworkStreamThrottler(std::move(owned_throttler)); |
| 375 | |
| 376 | return session; |
| 377 | } |
| 378 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 379 | } // namespace |
| 380 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 381 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 382 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 383 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 384 | // Important to restore the per-pool limit first, since the pool limit must |
| 385 | // always be greater than group limit, and the tests reduce both limits. |
| 386 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 387 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 388 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 389 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 390 | } |
| 391 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 392 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 393 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 394 | : ssl_(ASYNC, OK), |
| 395 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 396 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 397 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 398 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 399 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 400 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 401 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 402 | struct SimpleGetHelperResult { |
| 403 | int rv; |
| 404 | std::string status_line; |
| 405 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 406 | int64_t total_received_bytes; |
| 407 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 408 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 409 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 410 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 411 | }; |
| 412 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 413 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 414 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 415 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 416 | } |
| 417 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 418 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 419 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 420 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 421 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 422 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 423 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 424 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 425 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 426 | } |
| 427 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 428 | // Either |write_failure| specifies a write failure or |read_failure| |
| 429 | // specifies a read failure when using a reused socket. In either case, the |
| 430 | // failure should cause the network transaction to resend the request, and the |
| 431 | // other argument should be NULL. |
| 432 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 433 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 434 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 435 | // Either |write_failure| specifies a write failure or |read_failure| |
| 436 | // specifies a read failure when using a reused socket. In either case, the |
| 437 | // failure should cause the network transaction to resend the request, and the |
| 438 | // other argument should be NULL. |
| 439 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 440 | const MockRead* read_failure, |
| 441 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 442 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 443 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 444 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 445 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 446 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 447 | HttpRequestInfo request; |
| 448 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 449 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 450 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 451 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 452 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 453 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 454 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 455 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 456 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 457 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 458 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 459 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 460 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 461 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 462 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 463 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 464 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 465 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 466 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 467 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 468 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 469 | |
| 470 | // Even in the failure cases that use this function, connections are always |
| 471 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 472 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 473 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 474 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 475 | if (out.rv != OK) |
| 476 | return out; |
| 477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 479 | // Can't use ASSERT_* inside helper functions like this, so |
| 480 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 481 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 482 | out.rv = ERR_UNEXPECTED; |
| 483 | return out; |
| 484 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 485 | out.status_line = response->headers->GetStatusLine(); |
| 486 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 487 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 488 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 489 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 490 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 491 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 492 | EXPECT_EQ(got_endpoint, |
| 493 | out.remote_endpoint_after_start.address().size() > 0); |
| 494 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 495 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 496 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 497 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 498 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 499 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 500 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 501 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 502 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 503 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 504 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 505 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 506 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 507 | std::string line; |
| 508 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 509 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 510 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 511 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 512 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 513 | std::string value; |
| 514 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 515 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 516 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 517 | EXPECT_EQ("keep-alive", value); |
| 518 | |
| 519 | std::string response_headers; |
| 520 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 521 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 522 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 523 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 524 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 525 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 526 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 527 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 528 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 529 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 530 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 531 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 532 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 533 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 534 | MockWrite data_writes[] = { |
| 535 | MockWrite("GET / HTTP/1.1\r\n" |
| 536 | "Host: www.example.org\r\n" |
| 537 | "Connection: keep-alive\r\n\r\n"), |
| 538 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 539 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 540 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 541 | arraysize(data_writes)); |
| 542 | StaticSocketDataProvider* data[] = {&reads}; |
| 543 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 544 | |
| 545 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 546 | out.total_sent_bytes); |
| 547 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 548 | } |
| 549 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 550 | void AddSSLSocketData() { |
| 551 | ssl_.next_proto = kProtoHTTP2; |
| 552 | ssl_.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 553 | ASSERT_TRUE(ssl_.cert); |
| 554 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 555 | } |
| 556 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 557 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 558 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 559 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 560 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 561 | |
| 562 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 563 | |
| 564 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 565 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 566 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 567 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 568 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 569 | |
| 570 | // Original socket limits. Some tests set these. Safest to always restore |
| 571 | // them once each test has been run. |
| 572 | int old_max_group_sockets_; |
| 573 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 574 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 575 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 576 | namespace { |
| 577 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 578 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 579 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 580 | BeforeHeadersSentHandler() |
| 581 | : observed_before_headers_sent_with_proxy_(false), |
| 582 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 583 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 584 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 585 | HttpRequestHeaders* request_headers) { |
| 586 | observed_before_headers_sent_ = true; |
| 587 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 588 | !proxy_info.is_quic()) { |
| 589 | return; |
| 590 | } |
| 591 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 592 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 593 | } |
| 594 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 595 | bool observed_before_headers_sent_with_proxy() const { |
| 596 | return observed_before_headers_sent_with_proxy_; |
| 597 | } |
| 598 | |
| 599 | bool observed_before_headers_sent() const { |
| 600 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | std::string observed_proxy_server_uri() const { |
| 604 | return observed_proxy_server_uri_; |
| 605 | } |
| 606 | |
| 607 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 608 | bool observed_before_headers_sent_with_proxy_; |
| 609 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 610 | std::string observed_proxy_server_uri_; |
| 611 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 612 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 613 | }; |
| 614 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 615 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 616 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 617 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 618 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 619 | const int sizeof_row = strlen(row); |
| 620 | const int num_rows = static_cast<int>( |
| 621 | ceil(static_cast<float>(size) / sizeof_row)); |
| 622 | const int sizeof_data = num_rows * sizeof_row; |
| 623 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 624 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 625 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 626 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 627 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 628 | } |
| 629 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 630 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 631 | // Alternative functions that eliminate randomness and dependency on the local |
| 632 | // host name so that the generated NTLM messages are reproducible. |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 633 | void MockGenerateRandom1(uint8_t* output, size_t n) { |
| 634 | static const uint8_t bytes[] = {0x55, 0x29, 0x66, 0x26, |
| 635 | 0x6b, 0x9c, 0x73, 0x54}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 636 | static size_t current_byte = 0; |
| 637 | for (size_t i = 0; i < n; ++i) { |
| 638 | output[i] = bytes[current_byte++]; |
| 639 | current_byte %= arraysize(bytes); |
| 640 | } |
| 641 | } |
| 642 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 643 | void MockGenerateRandom2(uint8_t* output, size_t n) { |
| 644 | static const uint8_t bytes[] = {0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, |
| 645 | 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45, |
| 646 | 0x31, 0x5b, 0xd3, 0x1f}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 647 | static size_t current_byte = 0; |
| 648 | for (size_t i = 0; i < n; ++i) { |
| 649 | output[i] = bytes[current_byte++]; |
| 650 | current_byte %= arraysize(bytes); |
| 651 | } |
| 652 | } |
| 653 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 654 | std::string MockGetHostName() { |
| 655 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 656 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 657 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 658 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 659 | template<typename ParentPool> |
| 660 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 661 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 662 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 663 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 664 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 665 | const std::string last_group_name_received() const { |
| 666 | return last_group_name_; |
| 667 | } |
| 668 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 669 | int RequestSocket(const std::string& group_name, |
| 670 | const void* socket_params, |
| 671 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 672 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 673 | ClientSocketHandle* handle, |
| 674 | const CompletionCallback& callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 675 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 676 | last_group_name_ = group_name; |
| 677 | return ERR_IO_PENDING; |
| 678 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 679 | void CancelRequest(const std::string& group_name, |
| 680 | ClientSocketHandle* handle) override {} |
| 681 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 682 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 683 | int id) override {} |
| 684 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 685 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 686 | int IdleSocketCount() const override { return 0; } |
| 687 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 688 | return 0; |
| 689 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 690 | LoadState GetLoadState(const std::string& group_name, |
| 691 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 692 | return LOAD_STATE_IDLE; |
| 693 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 694 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 695 | return base::TimeDelta(); |
| 696 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 697 | |
| 698 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 699 | std::string last_group_name_; |
| 700 | }; |
| 701 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 702 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 703 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 704 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 705 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 706 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 707 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 708 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 709 | CaptureGroupNameSSLSocketPool; |
| 710 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 711 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 712 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 713 | HostResolver* host_resolver, |
| 714 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 715 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 716 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 717 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 718 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 719 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 720 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 721 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 722 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 723 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 724 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 725 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 726 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 727 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 728 | : SSLClientSocketPool(0, |
| 729 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 730 | cert_verifier, |
| 731 | NULL, |
| 732 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 733 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 734 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 735 | std::string(), |
| 736 | NULL, |
| 737 | NULL, |
| 738 | NULL, |
| 739 | NULL, |
| 740 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 741 | NULL) { |
| 742 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 743 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 744 | //----------------------------------------------------------------------------- |
| 745 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 746 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 747 | // configured for common cases. |
| 748 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 749 | if (!auth_challenge) |
| 750 | return false; |
| 751 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 752 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 753 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 754 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 755 | return true; |
| 756 | } |
| 757 | |
| 758 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 759 | if (!auth_challenge) |
| 760 | return false; |
| 761 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 762 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 763 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 764 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 765 | return true; |
| 766 | } |
| 767 | |
| 768 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 769 | if (!auth_challenge) |
| 770 | return false; |
| 771 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 772 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 773 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 774 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 775 | return true; |
| 776 | } |
| 777 | |
| 778 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 779 | if (!auth_challenge) |
| 780 | return false; |
| 781 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 782 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 783 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 784 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 785 | return true; |
| 786 | } |
| 787 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 788 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 789 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 790 | if (!auth_challenge) |
| 791 | return false; |
| 792 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 793 | EXPECT_EQ("http://172.22.68.17", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 794 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 795 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 796 | return true; |
| 797 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 798 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 799 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 800 | } // namespace |
| 801 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 802 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 803 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 804 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 805 | } |
| 806 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 807 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 808 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 809 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 810 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 811 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 812 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 813 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 814 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 815 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 816 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 817 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 818 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 819 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 820 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 821 | |
| 822 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 826 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 827 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 828 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 829 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 830 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 831 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 832 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 833 | EXPECT_THAT(out.rv, IsOk()); |
| 834 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 835 | EXPECT_EQ("hello world", out.response_data); |
| 836 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 837 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 838 | } |
| 839 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 840 | // Response with no status line, and a weird port. Should fail by default. |
| 841 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 842 | MockRead data_reads[] = { |
| 843 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 844 | }; |
| 845 | |
| 846 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 847 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 848 | |
| 849 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 850 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 851 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 852 | auto trans = |
| 853 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 854 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 855 | request.method = "GET"; |
| 856 | request.url = GURL("http://www.example.com:2000/"); |
| 857 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 858 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 859 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 860 | } |
| 861 | |
| 862 | // Response with no status line, and a weird port. Option to allow weird ports |
| 863 | // enabled. |
| 864 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 865 | MockRead data_reads[] = { |
| 866 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 867 | }; |
| 868 | |
| 869 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 870 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 871 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 872 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 873 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 874 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 875 | auto trans = |
| 876 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 877 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 878 | request.method = "GET"; |
| 879 | request.url = GURL("http://www.example.com:2000/"); |
| 880 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 881 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 882 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 883 | |
| 884 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 885 | ASSERT_TRUE(info->headers); |
| 886 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 887 | |
| 888 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 889 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 890 | } |
| 891 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 892 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 893 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 894 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 895 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 896 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 897 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 898 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 899 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 900 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 901 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 902 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 903 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 904 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 905 | } |
| 906 | |
| 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, StatusLineJunk4Bytes) { |
[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("\n\nQJHTTP/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 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 923 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[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("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[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)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 930 | EXPECT_THAT(out.rv, IsOk()); |
| 931 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 932 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 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 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 938 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[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("\n"), |
| 941 | MockRead("\n"), |
| 942 | MockRead("Q"), |
| 943 | MockRead("J"), |
| 944 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 945 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 946 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 947 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 948 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 949 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 950 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 951 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 952 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 953 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 957 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 958 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 959 | MockRead("HTT"), |
[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)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 964 | EXPECT_THAT(out.rv, IsOk()); |
| 965 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 966 | EXPECT_EQ("HTT", out.response_data); |
| 967 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 968 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 969 | } |
| 970 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 971 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 972 | // persistent connection. The response should still terminate since a 204 |
| 973 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 974 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 975 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 976 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 977 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 978 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 979 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 980 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 981 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 982 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 983 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 984 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 985 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 986 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 987 | int64_t response_size = reads_size - strlen(junk); |
| 988 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 989 | } |
| 990 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 991 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 992 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 993 | std::string final_chunk = "0\r\n\r\n"; |
| 994 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 995 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 996 | MockRead data_reads[] = { |
| 997 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 998 | MockRead("5\r\nHello\r\n"), |
| 999 | MockRead("1\r\n"), |
| 1000 | MockRead(" \r\n"), |
| 1001 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1002 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1003 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1004 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1005 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1006 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1007 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1008 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1009 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1010 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1011 | int64_t response_size = reads_size - extra_data.size(); |
| 1012 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1013 | } |
| 1014 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1015 | // Next tests deal with http://crbug.com/56344. |
| 1016 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1017 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1018 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1019 | MockRead data_reads[] = { |
| 1020 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1021 | MockRead("Content-Length: 10\r\n"), |
| 1022 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1023 | }; |
| 1024 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1025 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1026 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1027 | } |
| 1028 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1029 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1030 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1031 | MockRead data_reads[] = { |
| 1032 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1033 | MockRead("Content-Length: 5\r\n"), |
| 1034 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1035 | MockRead("Hello"), |
| 1036 | }; |
| 1037 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1038 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1039 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1040 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1041 | EXPECT_EQ("Hello", out.response_data); |
| 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 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1046 | // More than 2 dupes. |
| 1047 | { |
| 1048 | MockRead data_reads[] = { |
| 1049 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1050 | MockRead("Content-Length: 5\r\n"), |
| 1051 | MockRead("Content-Length: 5\r\n"), |
| 1052 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1053 | MockRead("Hello"), |
| 1054 | }; |
| 1055 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1056 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1057 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1058 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1059 | EXPECT_EQ("Hello", out.response_data); |
| 1060 | } |
| 1061 | // HTTP/1.0 |
| 1062 | { |
| 1063 | MockRead data_reads[] = { |
| 1064 | MockRead("HTTP/1.0 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.0 200 OK", out.status_line); |
| 1074 | EXPECT_EQ("Hello", out.response_data); |
| 1075 | } |
| 1076 | // 2 dupes and one mismatched. |
| 1077 | { |
| 1078 | MockRead data_reads[] = { |
| 1079 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1080 | MockRead("Content-Length: 10\r\n"), |
| 1081 | MockRead("Content-Length: 10\r\n"), |
| 1082 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1083 | }; |
| 1084 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1085 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1086 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1090 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1091 | MultipleContentLengthHeadersTransferEncoding) { |
| 1092 | MockRead data_reads[] = { |
| 1093 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1094 | MockRead("Content-Length: 666\r\n"), |
| 1095 | MockRead("Content-Length: 1337\r\n"), |
| 1096 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1097 | MockRead("5\r\nHello\r\n"), |
| 1098 | MockRead("1\r\n"), |
| 1099 | MockRead(" \r\n"), |
| 1100 | MockRead("5\r\nworld\r\n"), |
| 1101 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1102 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1103 | }; |
| 1104 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1105 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1106 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1107 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1108 | EXPECT_EQ("Hello world", out.response_data); |
| 1109 | } |
| 1110 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1111 | // Next tests deal with http://crbug.com/98895. |
| 1112 | |
| 1113 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1114 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1115 | MockRead data_reads[] = { |
| 1116 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1117 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1118 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1119 | MockRead("Hello"), |
| 1120 | }; |
| 1121 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1122 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1123 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1124 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1125 | EXPECT_EQ("Hello", out.response_data); |
| 1126 | } |
| 1127 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1128 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1129 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[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=\"greetings.txt\"r\n"), |
| 1133 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1134 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1135 | MockRead("Hello"), |
| 1136 | }; |
| 1137 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1138 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1139 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1140 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1141 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1145 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1146 | MockRead data_reads[] = { |
| 1147 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1148 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1149 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1150 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1151 | MockRead("Hello"), |
| 1152 | }; |
| 1153 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1154 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1155 | EXPECT_THAT(out.rv, |
| 1156 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1157 | } |
| 1158 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1159 | // Checks that two identical Location headers result in no error. |
| 1160 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1161 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1162 | MockRead data_reads[] = { |
| 1163 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1164 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1165 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1166 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1167 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1168 | }; |
| 1169 | |
| 1170 | HttpRequestInfo request; |
| 1171 | request.method = "GET"; |
| 1172 | request.url = GURL("http://redirect.com/"); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1173 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1174 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1175 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1176 | |
| 1177 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1178 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1180 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1181 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1182 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1183 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1184 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1185 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1186 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1187 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1188 | ASSERT_TRUE(response); |
| 1189 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1190 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1191 | std::string url; |
| 1192 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1193 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1194 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1195 | } |
| 1196 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1197 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1198 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1199 | MockRead data_reads[] = { |
| 1200 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1201 | MockRead("Location: http://good.com/\r\n"), |
| 1202 | MockRead("Location: http://evil.com/\r\n"), |
| 1203 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1204 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1205 | }; |
| 1206 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1207 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1208 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1209 | } |
| 1210 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1211 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1212 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1213 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1214 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1215 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1216 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1217 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1218 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1219 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1220 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1221 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1222 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1223 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1224 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1225 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1226 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1227 | "Host: www.example.org\r\n" |
| 1228 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1229 | }; |
| 1230 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1231 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1232 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1233 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1234 | // No response body because the test stops reading here. |
| 1235 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1236 | }; |
| 1237 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1238 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1239 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1240 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1241 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1242 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1243 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1244 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1245 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1246 | |
| 1247 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1248 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1249 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1250 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1251 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1252 | |
| 1253 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1254 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1255 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1256 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1257 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1258 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1259 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1260 | |
| 1261 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1262 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1263 | bool has_server_header = response->headers->EnumerateHeader( |
| 1264 | &iter, "Server", &server_header); |
| 1265 | EXPECT_TRUE(has_server_header); |
| 1266 | EXPECT_EQ("Blah", server_header); |
| 1267 | |
| 1268 | // Reading should give EOF right away, since there is no message body |
| 1269 | // (despite non-zero content-length). |
| 1270 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1271 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1272 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1273 | EXPECT_EQ("", response_data); |
| 1274 | } |
| 1275 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1276 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1277 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1278 | |
| 1279 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1280 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1281 | MockRead("hello"), |
| 1282 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1283 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1284 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1285 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1286 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1287 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1288 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1289 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1290 | "hello", "world" |
| 1291 | }; |
| 1292 | |
| 1293 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1294 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1295 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1296 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1297 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1298 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1299 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1300 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1301 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1302 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1303 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1304 | |
| 1305 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1306 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1307 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1308 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1309 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1310 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1311 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1312 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1313 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1314 | |
| 1315 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1316 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1317 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1318 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1319 | } |
| 1320 | } |
| 1321 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1322 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1323 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1324 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 1325 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1326 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1327 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1328 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1329 | request.method = "POST"; |
| 1330 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1331 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1332 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1333 | // Check the upload progress returned before initialization is correct. |
| 1334 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1335 | EXPECT_EQ(0u, progress.size()); |
| 1336 | EXPECT_EQ(0u, progress.position()); |
| 1337 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1338 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1339 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1340 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1341 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1342 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1343 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1344 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1345 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1346 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1347 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1348 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1349 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1350 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1351 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1352 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1353 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1354 | |
| 1355 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1356 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1357 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1358 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1359 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1360 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1361 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1362 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1363 | |
| 1364 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1365 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1366 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1367 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1368 | } |
| 1369 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1370 | // This test is almost the same as Ignores100 above, but the response contains |
| 1371 | // 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] | 1372 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1373 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1374 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1375 | request.method = "GET"; |
| 1376 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1377 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1378 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1379 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1380 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1381 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1382 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1383 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1384 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1385 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1386 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1387 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1388 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1389 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1390 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1391 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1392 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1394 | |
| 1395 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1396 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1398 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1399 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1400 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1401 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1402 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1403 | |
| 1404 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1405 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1406 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1407 | EXPECT_EQ("hello world", response_data); |
| 1408 | } |
| 1409 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1410 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1411 | HttpRequestInfo request; |
| 1412 | request.method = "POST"; |
| 1413 | request.url = GURL("http://www.foo.com/"); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1414 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1416 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1417 | |
| 1418 | MockRead data_reads[] = { |
| 1419 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1420 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1421 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1422 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1423 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1424 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1425 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1426 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1427 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1428 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1429 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1430 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1431 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1432 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1433 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1434 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1435 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1436 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1437 | } |
| 1438 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1439 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1440 | HttpRequestInfo request; |
| 1441 | request.method = "POST"; |
| 1442 | request.url = GURL("http://www.foo.com/"); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1443 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1444 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1445 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1446 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1447 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1448 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1449 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1450 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1451 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1452 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1453 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1454 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1455 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1457 | |
| 1458 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1459 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1460 | } |
| 1461 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1462 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1463 | const MockWrite* write_failure, |
| 1464 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1465 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1466 | request.method = "GET"; |
| 1467 | request.url = GURL("http://www.foo.com/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1468 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1469 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1470 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1472 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1473 | // Written data for successfully sending both requests. |
| 1474 | MockWrite data1_writes[] = { |
| 1475 | MockWrite("GET / HTTP/1.1\r\n" |
| 1476 | "Host: www.foo.com\r\n" |
| 1477 | "Connection: keep-alive\r\n\r\n"), |
| 1478 | MockWrite("GET / HTTP/1.1\r\n" |
| 1479 | "Host: www.foo.com\r\n" |
| 1480 | "Connection: keep-alive\r\n\r\n") |
| 1481 | }; |
| 1482 | |
| 1483 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1484 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1485 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1486 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1487 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1488 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1489 | |
| 1490 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1491 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1492 | data1_writes[1] = *write_failure; |
| 1493 | } else { |
| 1494 | ASSERT_TRUE(read_failure); |
| 1495 | data1_reads[2] = *read_failure; |
| 1496 | } |
| 1497 | |
| 1498 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1499 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1500 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1501 | |
| 1502 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1503 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1504 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1505 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1506 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1507 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1508 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1509 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1510 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1511 | "hello", "world" |
| 1512 | }; |
| 1513 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1514 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1515 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1516 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1517 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1518 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1519 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1520 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1521 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1522 | |
| 1523 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1524 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1525 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1526 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1527 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1528 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1529 | if (i == 0) { |
| 1530 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1531 | } else { |
| 1532 | // The second request should be using a new socket. |
| 1533 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1534 | } |
| 1535 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1536 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1537 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1538 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1539 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1540 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1541 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1542 | |
| 1543 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1544 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1545 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1546 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1547 | } |
| 1548 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1549 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1550 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1551 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1552 | const MockRead* read_failure, |
| 1553 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1554 | HttpRequestInfo request; |
| 1555 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1556 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1557 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1558 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1559 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1560 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1561 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1562 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1563 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1564 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1565 | ssl1.next_proto = kProtoHTTP2; |
| 1566 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1567 | } |
| 1568 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1570 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1571 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1572 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1573 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1574 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1575 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1576 | SpdySerializedFrame spdy_data( |
| 1577 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1578 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1579 | // HTTP/1.1 versions of the request and response. |
| 1580 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1581 | "Host: www.foo.com\r\n" |
| 1582 | "Connection: keep-alive\r\n\r\n"; |
| 1583 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1584 | const char kHttpData[] = "hello"; |
| 1585 | |
| 1586 | std::vector<MockRead> data1_reads; |
| 1587 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1588 | if (write_failure) { |
| 1589 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1590 | data1_writes.push_back(*write_failure); |
| 1591 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1592 | } else { |
| 1593 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1594 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1595 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1596 | } else { |
| 1597 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1598 | } |
| 1599 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1600 | } |
| 1601 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1602 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1603 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1604 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1605 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1606 | std::vector<MockRead> data2_reads; |
| 1607 | std::vector<MockWrite> data2_writes; |
| 1608 | |
| 1609 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1610 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1611 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1612 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1613 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1614 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1615 | } else { |
| 1616 | data2_writes.push_back( |
| 1617 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1618 | |
| 1619 | data2_reads.push_back( |
| 1620 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1621 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1622 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1623 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1624 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1625 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1626 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1627 | |
| 1628 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1629 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1630 | // Wait for the preconnect to complete. |
| 1631 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1632 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1633 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1634 | |
| 1635 | // Make the request. |
| 1636 | TestCompletionCallback callback; |
| 1637 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1638 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1639 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1640 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1642 | |
| 1643 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1644 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1645 | |
| 1646 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1647 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1648 | TestLoadTimingNotReused( |
| 1649 | load_timing_info, |
| 1650 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1651 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1652 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1653 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1654 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1655 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1656 | if (response->was_fetched_via_spdy) { |
| 1657 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1658 | } else { |
| 1659 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1660 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1661 | |
| 1662 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1663 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1664 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1665 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1666 | } |
| 1667 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1668 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1669 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1670 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1671 | } |
| 1672 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1673 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1674 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1675 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1676 | } |
| 1677 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1678 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1679 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1680 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1681 | } |
| 1682 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1683 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1684 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1685 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1686 | MockRead read_failure(SYNCHRONOUS, |
| 1687 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1688 | "Connection: Keep-Alive\r\n" |
| 1689 | "Content-Length: 6\r\n\r\n" |
| 1690 | "Pickle"); |
| 1691 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1692 | } |
| 1693 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1694 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1695 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1696 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1697 | } |
| 1698 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1699 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1700 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1701 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1702 | } |
| 1703 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1704 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1705 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1706 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1707 | } |
| 1708 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1709 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1710 | MockRead read_failure(ASYNC, OK); // EOF |
| 1711 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1712 | } |
| 1713 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1714 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1715 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1716 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1717 | MockRead read_failure(SYNCHRONOUS, |
| 1718 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1719 | "Connection: Keep-Alive\r\n" |
| 1720 | "Content-Length: 6\r\n\r\n" |
| 1721 | "Pickle"); |
| 1722 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1723 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1724 | } |
| 1725 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1726 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1727 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1728 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1729 | } |
| 1730 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1731 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1732 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1733 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1734 | } |
| 1735 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1736 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1737 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1738 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1739 | } |
| 1740 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1741 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1742 | MockRead read_failure(ASYNC, OK); // EOF |
| 1743 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1744 | } |
| 1745 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1746 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1747 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1748 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1749 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1750 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1751 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1752 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1753 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1754 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1755 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1756 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1757 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1758 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1759 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1760 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1761 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1762 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1763 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1764 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1765 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1766 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1767 | |
| 1768 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1769 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1770 | |
| 1771 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1772 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1773 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | // What do various browsers do when the server closes a non-keepalive |
| 1777 | // connection without sending any response header or body? |
| 1778 | // |
| 1779 | // IE7: error page |
| 1780 | // Safari 3.1.2 (Windows): error page |
| 1781 | // Firefox 3.0.1: blank page |
| 1782 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1783 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1784 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1785 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1786 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1787 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1788 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1789 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1790 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1791 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1792 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1793 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1794 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1795 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1796 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1797 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1798 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1799 | // destructor in such situations. |
| 1800 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1801 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1802 | HttpRequestInfo request; |
| 1803 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1804 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1805 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1806 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1807 | auto trans = |
| 1808 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1809 | |
| 1810 | MockRead data_reads[] = { |
| 1811 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1812 | MockRead("Connection: keep-alive\r\n"), |
| 1813 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1814 | MockRead("hello"), |
| 1815 | MockRead(SYNCHRONOUS, 0), |
| 1816 | }; |
| 1817 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1818 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1819 | |
| 1820 | TestCompletionCallback callback; |
| 1821 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1822 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1823 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1824 | |
| 1825 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1826 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1827 | |
| 1828 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1829 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1830 | if (rv == ERR_IO_PENDING) |
| 1831 | rv = callback.WaitForResult(); |
| 1832 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1833 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1834 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1835 | |
| 1836 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1837 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1838 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1839 | } |
| 1840 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1841 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1842 | HttpRequestInfo request; |
| 1843 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1844 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1845 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1846 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1847 | auto trans = |
| 1848 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1849 | |
| 1850 | MockRead data_reads[] = { |
| 1851 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1852 | MockRead("Connection: keep-alive\r\n"), |
| 1853 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1854 | MockRead(SYNCHRONOUS, 0), |
| 1855 | }; |
| 1856 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1857 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1858 | |
| 1859 | TestCompletionCallback callback; |
| 1860 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1861 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1862 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1863 | |
| 1864 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1865 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1866 | |
| 1867 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1868 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1869 | if (rv == ERR_IO_PENDING) |
| 1870 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1871 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1872 | |
| 1873 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1874 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1875 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1876 | } |
| 1877 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1878 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1879 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1880 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1881 | HttpRequestInfo request; |
| 1882 | request.method = "GET"; |
| 1883 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1884 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1885 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1886 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1887 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1888 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1889 | const char* request_data = |
| 1890 | "GET / HTTP/1.1\r\n" |
| 1891 | "Host: www.foo.com\r\n" |
| 1892 | "Connection: keep-alive\r\n\r\n"; |
| 1893 | MockWrite data_writes[] = { |
| 1894 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1895 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1896 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1897 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1898 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1899 | }; |
| 1900 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1901 | // Note that because all these reads happen in the same |
| 1902 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1903 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1904 | MockRead data_reads[] = { |
| 1905 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1906 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1907 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1908 | MockRead(ASYNC, 7, |
| 1909 | "HTTP/1.1 302 Found\r\n" |
| 1910 | "Content-Length: 0\r\n\r\n"), |
| 1911 | MockRead(ASYNC, 9, |
| 1912 | "HTTP/1.1 302 Found\r\n" |
| 1913 | "Content-Length: 5\r\n\r\n" |
| 1914 | "hello"), |
| 1915 | MockRead(ASYNC, 11, |
| 1916 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1917 | "Content-Length: 0\r\n\r\n"), |
| 1918 | MockRead(ASYNC, 13, |
| 1919 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1920 | "Content-Length: 5\r\n\r\n" |
| 1921 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1922 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1923 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1924 | // the set_busy_before_sync_reads(true) call, while the |
| 1925 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1926 | // reuseable. See http://crbug.com/544255. |
| 1927 | MockRead(ASYNC, 15, |
| 1928 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1929 | "Content-Length: 5\r\n\r\n"), |
| 1930 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1931 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1932 | MockRead(ASYNC, 18, |
| 1933 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1934 | "Content-Length: 5\r\n\r\n" |
| 1935 | "he"), |
| 1936 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1937 | |
| 1938 | // The body of the final request is actually read. |
| 1939 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1940 | MockRead(ASYNC, 22, "hello"), |
| 1941 | }; |
| 1942 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1943 | arraysize(data_writes)); |
| 1944 | data.set_busy_before_sync_reads(true); |
| 1945 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1946 | |
| 1947 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1948 | std::string response_lines[kNumUnreadBodies]; |
| 1949 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1950 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1951 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1952 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1953 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1954 | auto trans = base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 1955 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1956 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1957 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1958 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1959 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1960 | LoadTimingInfo load_timing_info; |
| 1961 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1962 | if (i == 0) { |
| 1963 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1964 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1965 | } else { |
| 1966 | TestLoadTimingReused(load_timing_info); |
| 1967 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1968 | } |
| 1969 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1970 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1971 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1972 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1973 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1974 | response_lines[i] = response->headers->GetStatusLine(); |
| 1975 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1976 | // Delete the transaction without reading the response bodies. Then spin |
| 1977 | // the message loop, so the response bodies are drained. |
| 1978 | trans.reset(); |
| 1979 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1980 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1981 | |
| 1982 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1983 | "HTTP/1.1 204 No Content", |
| 1984 | "HTTP/1.1 205 Reset Content", |
| 1985 | "HTTP/1.1 304 Not Modified", |
| 1986 | "HTTP/1.1 302 Found", |
| 1987 | "HTTP/1.1 302 Found", |
| 1988 | "HTTP/1.1 301 Moved Permanently", |
| 1989 | "HTTP/1.1 301 Moved Permanently", |
| 1990 | "HTTP/1.1 200 Hunky-Dory", |
| 1991 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1992 | }; |
| 1993 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1994 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1995 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1996 | |
| 1997 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1998 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2000 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2001 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2002 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2003 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2004 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2005 | ASSERT_TRUE(response); |
| 2006 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2007 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2008 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2009 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2010 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2011 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2012 | } |
| 2013 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2014 | // Sockets that receive extra data after a response is complete should not be |
| 2015 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2016 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2018 | MockWrite data_writes1[] = { |
| 2019 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2020 | "Host: www.borked.com\r\n" |
| 2021 | "Connection: keep-alive\r\n\r\n"), |
| 2022 | }; |
| 2023 | |
| 2024 | MockRead data_reads1[] = { |
| 2025 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2026 | "Connection: keep-alive\r\n" |
| 2027 | "Content-Length: 22\r\n\r\n" |
| 2028 | "This server is borked."), |
| 2029 | }; |
| 2030 | |
| 2031 | MockWrite data_writes2[] = { |
| 2032 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2033 | "Host: www.borked.com\r\n" |
| 2034 | "Connection: keep-alive\r\n\r\n"), |
| 2035 | }; |
| 2036 | |
| 2037 | MockRead data_reads2[] = { |
| 2038 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2039 | "Content-Length: 3\r\n\r\n" |
| 2040 | "foo"), |
| 2041 | }; |
| 2042 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2043 | data_writes1, arraysize(data_writes1)); |
| 2044 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2045 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2046 | data_writes2, arraysize(data_writes2)); |
| 2047 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2048 | |
| 2049 | TestCompletionCallback callback; |
| 2050 | HttpRequestInfo request1; |
| 2051 | request1.method = "HEAD"; |
| 2052 | request1.url = GURL("http://www.borked.com/"); |
| 2053 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2054 | auto trans1 = |
| 2055 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2056 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2057 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2058 | |
| 2059 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2060 | ASSERT_TRUE(response1); |
| 2061 | ASSERT_TRUE(response1->headers); |
| 2062 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2063 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2064 | |
| 2065 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2066 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2067 | EXPECT_EQ("", response_data1); |
| 2068 | // Deleting the transaction attempts to release the socket back into the |
| 2069 | // socket pool. |
| 2070 | trans1.reset(); |
| 2071 | |
| 2072 | HttpRequestInfo request2; |
| 2073 | request2.method = "GET"; |
| 2074 | request2.url = GURL("http://www.borked.com/foo"); |
| 2075 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2076 | auto trans2 = |
| 2077 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2078 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2079 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2080 | |
| 2081 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2082 | ASSERT_TRUE(response2); |
| 2083 | ASSERT_TRUE(response2->headers); |
| 2084 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2085 | |
| 2086 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2087 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2088 | EXPECT_EQ("foo", response_data2); |
| 2089 | } |
| 2090 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2091 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2092 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2093 | MockWrite data_writes1[] = { |
| 2094 | MockWrite("GET / HTTP/1.1\r\n" |
| 2095 | "Host: www.borked.com\r\n" |
| 2096 | "Connection: keep-alive\r\n\r\n"), |
| 2097 | }; |
| 2098 | |
| 2099 | MockRead data_reads1[] = { |
| 2100 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2101 | "Connection: keep-alive\r\n" |
| 2102 | "Content-Length: 22\r\n\r\n" |
| 2103 | "This server is borked." |
| 2104 | "Bonus data!"), |
| 2105 | }; |
| 2106 | |
| 2107 | MockWrite data_writes2[] = { |
| 2108 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2109 | "Host: www.borked.com\r\n" |
| 2110 | "Connection: keep-alive\r\n\r\n"), |
| 2111 | }; |
| 2112 | |
| 2113 | MockRead data_reads2[] = { |
| 2114 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2115 | "Content-Length: 3\r\n\r\n" |
| 2116 | "foo"), |
| 2117 | }; |
| 2118 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2119 | data_writes1, arraysize(data_writes1)); |
| 2120 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2121 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2122 | data_writes2, arraysize(data_writes2)); |
| 2123 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2124 | |
| 2125 | TestCompletionCallback callback; |
| 2126 | HttpRequestInfo request1; |
| 2127 | request1.method = "GET"; |
| 2128 | request1.url = GURL("http://www.borked.com/"); |
| 2129 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2130 | auto trans1 = |
| 2131 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2132 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2133 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2134 | |
| 2135 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2136 | ASSERT_TRUE(response1); |
| 2137 | ASSERT_TRUE(response1->headers); |
| 2138 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2139 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2140 | |
| 2141 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2142 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2143 | EXPECT_EQ("This server is borked.", response_data1); |
| 2144 | // Deleting the transaction attempts to release the socket back into the |
| 2145 | // socket pool. |
| 2146 | trans1.reset(); |
| 2147 | |
| 2148 | HttpRequestInfo request2; |
| 2149 | request2.method = "GET"; |
| 2150 | request2.url = GURL("http://www.borked.com/foo"); |
| 2151 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2152 | auto trans2 = |
| 2153 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2154 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2155 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2156 | |
| 2157 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2158 | ASSERT_TRUE(response2); |
| 2159 | ASSERT_TRUE(response2->headers); |
| 2160 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2161 | |
| 2162 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2163 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2164 | EXPECT_EQ("foo", response_data2); |
| 2165 | } |
| 2166 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2167 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2168 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2169 | MockWrite data_writes1[] = { |
| 2170 | MockWrite("GET / HTTP/1.1\r\n" |
| 2171 | "Host: www.borked.com\r\n" |
| 2172 | "Connection: keep-alive\r\n\r\n"), |
| 2173 | }; |
| 2174 | |
| 2175 | MockRead data_reads1[] = { |
| 2176 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2177 | "Connection: keep-alive\r\n" |
| 2178 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2179 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2180 | MockRead("0\r\n\r\nBonus data!"), |
| 2181 | }; |
| 2182 | |
| 2183 | MockWrite data_writes2[] = { |
| 2184 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2185 | "Host: www.borked.com\r\n" |
| 2186 | "Connection: keep-alive\r\n\r\n"), |
| 2187 | }; |
| 2188 | |
| 2189 | MockRead data_reads2[] = { |
| 2190 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2191 | "Content-Length: 3\r\n\r\n" |
| 2192 | "foo"), |
| 2193 | }; |
| 2194 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2195 | data_writes1, arraysize(data_writes1)); |
| 2196 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2197 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2198 | data_writes2, arraysize(data_writes2)); |
| 2199 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2200 | |
| 2201 | TestCompletionCallback callback; |
| 2202 | HttpRequestInfo request1; |
| 2203 | request1.method = "GET"; |
| 2204 | request1.url = GURL("http://www.borked.com/"); |
| 2205 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2206 | auto trans1 = |
| 2207 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2208 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2209 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2210 | |
| 2211 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2212 | ASSERT_TRUE(response1); |
| 2213 | ASSERT_TRUE(response1->headers); |
| 2214 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2215 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2216 | |
| 2217 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2218 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2219 | EXPECT_EQ("This server is borked.", response_data1); |
| 2220 | // Deleting the transaction attempts to release the socket back into the |
| 2221 | // socket pool. |
| 2222 | trans1.reset(); |
| 2223 | |
| 2224 | HttpRequestInfo request2; |
| 2225 | request2.method = "GET"; |
| 2226 | request2.url = GURL("http://www.borked.com/foo"); |
| 2227 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2228 | auto trans2 = |
| 2229 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2230 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2231 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2232 | |
| 2233 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2234 | ASSERT_TRUE(response2); |
| 2235 | ASSERT_TRUE(response2->headers); |
| 2236 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2237 | |
| 2238 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2239 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2240 | EXPECT_EQ("foo", response_data2); |
| 2241 | } |
| 2242 | |
| 2243 | // This is a little different from the others - it tests the case that the |
| 2244 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2245 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2246 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2247 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2248 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2249 | MockWrite data_writes1[] = { |
| 2250 | MockWrite("GET / HTTP/1.1\r\n" |
| 2251 | "Host: www.borked.com\r\n" |
| 2252 | "Connection: keep-alive\r\n\r\n"), |
| 2253 | }; |
| 2254 | |
| 2255 | MockRead data_reads1[] = { |
| 2256 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2257 | "Connection: keep-alive\r\n" |
| 2258 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2259 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2260 | MockRead("0\r\n\r\nBonus data!"), |
| 2261 | }; |
| 2262 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2263 | data_writes1, arraysize(data_writes1)); |
| 2264 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2265 | |
| 2266 | TestCompletionCallback callback; |
| 2267 | HttpRequestInfo request1; |
| 2268 | request1.method = "GET"; |
| 2269 | request1.url = GURL("http://www.borked.com/"); |
| 2270 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2271 | auto trans = |
| 2272 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 2273 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2274 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2275 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2276 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2277 | ASSERT_TRUE(response1); |
| 2278 | ASSERT_TRUE(response1->headers); |
| 2279 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2280 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2281 | |
| 2282 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2283 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2284 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2285 | |
| 2286 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2287 | // socket can't be reused, rather than returning it to the socket pool. |
| 2288 | base::RunLoop().RunUntilIdle(); |
| 2289 | |
| 2290 | // There should be no idle sockets in the pool. |
| 2291 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2292 | } |
| 2293 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2294 | // Test the request-challenge-retry sequence for basic auth. |
| 2295 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2296 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2297 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2298 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2299 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2300 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2301 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2302 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2303 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2304 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2305 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2306 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2307 | MockWrite( |
| 2308 | "GET / HTTP/1.1\r\n" |
| 2309 | "Host: www.example.org\r\n" |
| 2310 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2311 | }; |
| 2312 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2313 | MockRead data_reads1[] = { |
| 2314 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2315 | // Give a couple authenticate options (only the middle one is actually |
| 2316 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2317 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2318 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2319 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2320 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2321 | // Large content-length -- won't matter, as connection will be reset. |
| 2322 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2323 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2324 | }; |
| 2325 | |
| 2326 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2327 | // be issuing -- the final header line contains the credentials. |
| 2328 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2329 | MockWrite( |
| 2330 | "GET / HTTP/1.1\r\n" |
| 2331 | "Host: www.example.org\r\n" |
| 2332 | "Connection: keep-alive\r\n" |
| 2333 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2334 | }; |
| 2335 | |
| 2336 | // Lastly, the server responds with the actual content. |
| 2337 | MockRead data_reads2[] = { |
| 2338 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2339 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2340 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2341 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2342 | }; |
| 2343 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2344 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2345 | data_writes1, arraysize(data_writes1)); |
| 2346 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2347 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2348 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2349 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2350 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2351 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2352 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2353 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2354 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2355 | |
| 2356 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2357 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2358 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2359 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2360 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2361 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2362 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2363 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2364 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2365 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2366 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2367 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2368 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2369 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2370 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2371 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2372 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2373 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2374 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2375 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2376 | |
| 2377 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2378 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2379 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2380 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2381 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2382 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2383 | // The load timing after restart should have a new socket ID, and times after |
| 2384 | // those of the first load timing. |
| 2385 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2386 | load_timing_info2.connect_timing.connect_start); |
| 2387 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2388 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2389 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2390 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2391 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2392 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2394 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2395 | ASSERT_TRUE(response); |
| 2396 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2397 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2398 | } |
| 2399 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2400 | // Test the request-challenge-retry sequence for basic auth. |
| 2401 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2402 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2403 | HttpRequestInfo request; |
| 2404 | request.method = "GET"; |
| 2405 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2406 | |
| 2407 | TestNetLog log; |
| 2408 | MockHostResolver* resolver = new MockHostResolver(); |
| 2409 | session_deps_.net_log = &log; |
| 2410 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2411 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2412 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2413 | |
| 2414 | resolver->rules()->ClearRules(); |
| 2415 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2416 | |
| 2417 | MockWrite data_writes1[] = { |
| 2418 | MockWrite("GET / HTTP/1.1\r\n" |
| 2419 | "Host: www.example.org\r\n" |
| 2420 | "Connection: keep-alive\r\n\r\n"), |
| 2421 | }; |
| 2422 | |
| 2423 | MockRead data_reads1[] = { |
| 2424 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2425 | // Give a couple authenticate options (only the middle one is actually |
| 2426 | // supported). |
| 2427 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2428 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2429 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2430 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2431 | // Large content-length -- won't matter, as connection will be reset. |
| 2432 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2433 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2434 | }; |
| 2435 | |
| 2436 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2437 | // be issuing -- the final header line contains the credentials. |
| 2438 | MockWrite data_writes2[] = { |
| 2439 | MockWrite("GET / HTTP/1.1\r\n" |
| 2440 | "Host: www.example.org\r\n" |
| 2441 | "Connection: keep-alive\r\n" |
| 2442 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2443 | }; |
| 2444 | |
| 2445 | // Lastly, the server responds with the actual content. |
| 2446 | MockRead data_reads2[] = { |
| 2447 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2448 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2449 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2450 | }; |
| 2451 | |
| 2452 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2453 | data_writes1, arraysize(data_writes1)); |
| 2454 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2455 | data_writes2, arraysize(data_writes2)); |
| 2456 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2457 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2458 | |
| 2459 | TestCompletionCallback callback1; |
| 2460 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2461 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2462 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2463 | |
| 2464 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2465 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2466 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2467 | |
| 2468 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2469 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2470 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2471 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2472 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2473 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2474 | ASSERT_TRUE(response); |
| 2475 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2476 | |
| 2477 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2478 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2479 | ASSERT_FALSE(endpoint.address().empty()); |
| 2480 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2481 | |
| 2482 | resolver->rules()->ClearRules(); |
| 2483 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2484 | |
| 2485 | TestCompletionCallback callback2; |
| 2486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2487 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2488 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2489 | |
| 2490 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2491 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2492 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2493 | // The load timing after restart should have a new socket ID, and times after |
| 2494 | // those of the first load timing. |
| 2495 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2496 | load_timing_info2.connect_timing.connect_start); |
| 2497 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2498 | |
| 2499 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2500 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2501 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2502 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2503 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2504 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2505 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2506 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2507 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2509 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2510 | ASSERT_FALSE(endpoint.address().empty()); |
| 2511 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2512 | } |
| 2513 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2514 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2515 | HttpRequestInfo request; |
| 2516 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2517 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2518 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2519 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2520 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2521 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2522 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2523 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2524 | MockWrite( |
| 2525 | "GET / HTTP/1.1\r\n" |
| 2526 | "Host: www.example.org\r\n" |
| 2527 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2528 | }; |
| 2529 | |
| 2530 | MockRead data_reads[] = { |
| 2531 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2532 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2533 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2534 | // Large content-length -- won't matter, as connection will be reset. |
| 2535 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2536 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2537 | }; |
| 2538 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2539 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2540 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2541 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2542 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2543 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2544 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2545 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2546 | |
| 2547 | rv = callback.WaitForResult(); |
| 2548 | EXPECT_EQ(0, rv); |
| 2549 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2550 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2551 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2552 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2553 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2555 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2556 | ASSERT_TRUE(response); |
| 2557 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2558 | } |
| 2559 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2560 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2561 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2562 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2563 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2564 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2565 | // reused. See http://crbug.com/544255. |
| 2566 | for (int i = 0; i < 2; ++i) { |
| 2567 | HttpRequestInfo request; |
| 2568 | request.method = "GET"; |
| 2569 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2570 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2571 | TestNetLog log; |
| 2572 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2573 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2574 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2575 | MockWrite data_writes[] = { |
| 2576 | MockWrite(ASYNC, 0, |
| 2577 | "GET / HTTP/1.1\r\n" |
| 2578 | "Host: www.example.org\r\n" |
| 2579 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2580 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2581 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2582 | // be issuing -- the final header line contains the credentials. |
| 2583 | MockWrite(ASYNC, 6, |
| 2584 | "GET / HTTP/1.1\r\n" |
| 2585 | "Host: www.example.org\r\n" |
| 2586 | "Connection: keep-alive\r\n" |
| 2587 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2588 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2589 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2590 | MockRead data_reads[] = { |
| 2591 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2592 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2593 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2594 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2595 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2596 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2597 | // Lastly, the server responds with the actual content. |
| 2598 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2599 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2600 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2601 | MockRead(ASYNC, 10, "Hello"), |
| 2602 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2603 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2604 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2605 | arraysize(data_writes)); |
| 2606 | data.set_busy_before_sync_reads(true); |
| 2607 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2608 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2609 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2610 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2611 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2612 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2613 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2614 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2615 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2616 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2617 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2618 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2619 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2620 | ASSERT_TRUE(response); |
| 2621 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2622 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2623 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2624 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2625 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2626 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2627 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2628 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2629 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2630 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2631 | TestLoadTimingReused(load_timing_info2); |
| 2632 | // The load timing after restart should have the same socket ID, and times |
| 2633 | // those of the first load timing. |
| 2634 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2635 | load_timing_info2.send_start); |
| 2636 | 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] | 2637 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2638 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2639 | ASSERT_TRUE(response); |
| 2640 | EXPECT_FALSE(response->auth_challenge); |
| 2641 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2642 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2643 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2644 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2645 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2646 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2647 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2648 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2649 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2650 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2654 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2655 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2656 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2657 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2658 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2659 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2660 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2661 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2662 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2663 | MockWrite("GET / HTTP/1.1\r\n" |
| 2664 | "Host: www.example.org\r\n" |
| 2665 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2666 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2667 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2668 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2669 | MockWrite("GET / HTTP/1.1\r\n" |
| 2670 | "Host: www.example.org\r\n" |
| 2671 | "Connection: keep-alive\r\n" |
| 2672 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2673 | }; |
| 2674 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2675 | MockRead data_reads1[] = { |
| 2676 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2677 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2678 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2679 | |
| 2680 | // Lastly, the server responds with the actual content. |
| 2681 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2682 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2683 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2684 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2685 | }; |
| 2686 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2687 | // An incorrect reconnect would cause this to be read. |
| 2688 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2689 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2690 | }; |
| 2691 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2692 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2693 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2694 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2695 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2696 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2697 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2698 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2699 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2700 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2701 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2702 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2703 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2704 | |
| 2705 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2706 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2707 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2708 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2709 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2710 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2711 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2712 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2714 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2715 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2716 | |
| 2717 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2718 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2720 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2721 | ASSERT_TRUE(response); |
| 2722 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2723 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2727 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2728 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2729 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2730 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2731 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2732 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2733 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2734 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2735 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2736 | MockWrite("GET / HTTP/1.1\r\n" |
| 2737 | "Host: www.example.org\r\n" |
| 2738 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2739 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2740 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2741 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2742 | MockWrite("GET / HTTP/1.1\r\n" |
| 2743 | "Host: www.example.org\r\n" |
| 2744 | "Connection: keep-alive\r\n" |
| 2745 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2746 | }; |
| 2747 | |
| 2748 | // Respond with 5 kb of response body. |
| 2749 | std::string large_body_string("Unauthorized"); |
| 2750 | large_body_string.append(5 * 1024, ' '); |
| 2751 | large_body_string.append("\r\n"); |
| 2752 | |
| 2753 | MockRead data_reads1[] = { |
| 2754 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2755 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2756 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2757 | // 5134 = 12 + 5 * 1024 + 2 |
| 2758 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2759 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2760 | |
| 2761 | // Lastly, the server responds with the actual content. |
| 2762 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2763 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2764 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2765 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2766 | }; |
| 2767 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2768 | // An incorrect reconnect would cause this to be read. |
| 2769 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2770 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2771 | }; |
| 2772 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2773 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2774 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2775 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2776 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2777 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2778 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2779 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2780 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2781 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2782 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2783 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2784 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2785 | |
| 2786 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2787 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2788 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2789 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2790 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2791 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2792 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2793 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2794 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2795 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2796 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2797 | |
| 2798 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2799 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2800 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2801 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2802 | ASSERT_TRUE(response); |
| 2803 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2804 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2808 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2809 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2810 | HttpRequestInfo request; |
| 2811 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2812 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2813 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2815 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2816 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2817 | MockWrite( |
| 2818 | "GET / HTTP/1.1\r\n" |
| 2819 | "Host: www.example.org\r\n" |
| 2820 | "Connection: keep-alive\r\n\r\n"), |
| 2821 | // This simulates the seemingly successful write to a closed connection |
| 2822 | // if the bug is not fixed. |
| 2823 | MockWrite( |
| 2824 | "GET / HTTP/1.1\r\n" |
| 2825 | "Host: www.example.org\r\n" |
| 2826 | "Connection: keep-alive\r\n" |
| 2827 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2828 | }; |
| 2829 | |
| 2830 | MockRead data_reads1[] = { |
| 2831 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2832 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2833 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2834 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2835 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2836 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2837 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2838 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2839 | }; |
| 2840 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2841 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2842 | // be issuing -- the final header line contains the credentials. |
| 2843 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2844 | MockWrite( |
| 2845 | "GET / HTTP/1.1\r\n" |
| 2846 | "Host: www.example.org\r\n" |
| 2847 | "Connection: keep-alive\r\n" |
| 2848 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2849 | }; |
| 2850 | |
| 2851 | // Lastly, the server responds with the actual content. |
| 2852 | MockRead data_reads2[] = { |
| 2853 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2854 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2855 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2856 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2857 | }; |
| 2858 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2859 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2860 | data_writes1, arraysize(data_writes1)); |
| 2861 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2862 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2863 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2864 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2865 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2866 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2867 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2868 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2869 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2870 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2871 | |
| 2872 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2873 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2874 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2875 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2876 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2877 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2878 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2879 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2880 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2881 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2882 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2883 | |
| 2884 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2885 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2886 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2887 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2888 | ASSERT_TRUE(response); |
| 2889 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2890 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2891 | } |
| 2892 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2893 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2894 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2895 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2896 | HttpRequestInfo request; |
| 2897 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2898 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2899 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2900 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2901 | |
| 2902 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2903 | session_deps_.proxy_service = |
| 2904 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2905 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2906 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2907 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2908 | |
| 2909 | // Since we have proxy, should try to establish tunnel. |
| 2910 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2911 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2912 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2913 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2914 | }; |
| 2915 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2916 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2917 | // connection. |
| 2918 | MockRead data_reads1[] = { |
| 2919 | // No credentials. |
| 2920 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2921 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2922 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2923 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2924 | // Since the first connection couldn't be reused, need to establish another |
| 2925 | // once given credentials. |
| 2926 | MockWrite data_writes2[] = { |
| 2927 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2928 | // be issuing -- the final header line contains the credentials. |
| 2929 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2930 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2931 | "Proxy-Connection: keep-alive\r\n" |
| 2932 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2933 | |
| 2934 | MockWrite("GET / HTTP/1.1\r\n" |
| 2935 | "Host: www.example.org\r\n" |
| 2936 | "Connection: keep-alive\r\n\r\n"), |
| 2937 | }; |
| 2938 | |
| 2939 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2940 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2941 | |
| 2942 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2943 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2944 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2945 | MockRead(SYNCHRONOUS, "hello"), |
| 2946 | }; |
| 2947 | |
| 2948 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2949 | data_writes1, arraysize(data_writes1)); |
| 2950 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2951 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2952 | data_writes2, arraysize(data_writes2)); |
| 2953 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2954 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2955 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2956 | |
| 2957 | TestCompletionCallback callback1; |
| 2958 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2959 | auto trans = |
| 2960 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2961 | |
| 2962 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2963 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2964 | |
| 2965 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2966 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2967 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2968 | log.GetEntries(&entries); |
| 2969 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2970 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2971 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2972 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2973 | entries, pos, |
| 2974 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2975 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2976 | |
| 2977 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2978 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2979 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2980 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2981 | EXPECT_EQ(407, response->headers->response_code()); |
| 2982 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2983 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2984 | |
| 2985 | LoadTimingInfo load_timing_info; |
| 2986 | // CONNECT requests and responses are handled at the connect job level, so |
| 2987 | // the transaction does not yet have a connection. |
| 2988 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2989 | |
| 2990 | TestCompletionCallback callback2; |
| 2991 | |
| 2992 | rv = |
| 2993 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2995 | |
| 2996 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2997 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2998 | |
| 2999 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3000 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3001 | |
| 3002 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3003 | EXPECT_EQ(200, response->headers->response_code()); |
| 3004 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3005 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3006 | |
| 3007 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3008 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3009 | |
| 3010 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3011 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3012 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3013 | |
| 3014 | trans.reset(); |
| 3015 | session->CloseAllConnections(); |
| 3016 | } |
| 3017 | |
| 3018 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3019 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3020 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3021 | HttpRequestInfo request; |
| 3022 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3023 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3024 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3025 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3026 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3027 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3028 | session_deps_.proxy_service = |
| 3029 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3030 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3031 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3032 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3033 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3034 | // Since we have proxy, should try to establish tunnel. |
| 3035 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3036 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3037 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3038 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3039 | }; |
| 3040 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3041 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3042 | // connection. |
| 3043 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3044 | // No credentials. |
| 3045 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3046 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3047 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3048 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3049 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3050 | MockWrite data_writes2[] = { |
| 3051 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3052 | // be issuing -- the final header line contains the credentials. |
| 3053 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3054 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3055 | "Proxy-Connection: keep-alive\r\n" |
| 3056 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3057 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3058 | MockWrite("GET / HTTP/1.1\r\n" |
| 3059 | "Host: www.example.org\r\n" |
| 3060 | "Connection: keep-alive\r\n\r\n"), |
| 3061 | }; |
| 3062 | |
| 3063 | MockRead data_reads2[] = { |
| 3064 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3065 | |
| 3066 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3067 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3068 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3069 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3070 | }; |
| 3071 | |
| 3072 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3073 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3074 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3075 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3076 | data_writes2, arraysize(data_writes2)); |
| 3077 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3078 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3079 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3081 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3082 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3083 | auto trans = |
| 3084 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3085 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3086 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3087 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3088 | |
| 3089 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3090 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3091 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3092 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3093 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3094 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3095 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3096 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3097 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3098 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3099 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3100 | |
| 3101 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3102 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3103 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3104 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3105 | EXPECT_EQ(407, response->headers->response_code()); |
| 3106 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3107 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3108 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3109 | LoadTimingInfo load_timing_info; |
| 3110 | // CONNECT requests and responses are handled at the connect job level, so |
| 3111 | // the transaction does not yet have a connection. |
| 3112 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3113 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3114 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3115 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3116 | rv = trans->RestartWithAuth( |
| 3117 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3119 | |
| 3120 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3121 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3122 | |
| 3123 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3124 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3125 | |
| 3126 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3127 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3128 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3129 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3130 | |
| 3131 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3132 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3133 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3134 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3135 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3136 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3137 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3138 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3139 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3140 | } |
| 3141 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3142 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3143 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3144 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3145 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3146 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3147 | // reused. See http://crbug.com/544255. |
| 3148 | for (int i = 0; i < 2; ++i) { |
| 3149 | HttpRequestInfo request; |
| 3150 | request.method = "GET"; |
| 3151 | request.url = GURL("https://www.example.org/"); |
| 3152 | // Ensure that proxy authentication is attempted even |
| 3153 | // when the no authentication data flag is set. |
| 3154 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3155 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3156 | // Configure against proxy server "myproxy:70". |
| 3157 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3158 | BoundTestNetLog log; |
| 3159 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3160 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3161 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3162 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3163 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3164 | // Since we have proxy, should try to establish tunnel. |
| 3165 | MockWrite data_writes1[] = { |
| 3166 | MockWrite(ASYNC, 0, |
| 3167 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3168 | "Host: www.example.org:443\r\n" |
| 3169 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3170 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3171 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3172 | // be issuing -- the final header line contains the credentials. |
| 3173 | MockWrite(ASYNC, 3, |
| 3174 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3175 | "Host: www.example.org:443\r\n" |
| 3176 | "Proxy-Connection: keep-alive\r\n" |
| 3177 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3178 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3179 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3180 | // The proxy responds to the connect with a 407, using a persistent |
| 3181 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3182 | MockRead data_reads1[] = { |
| 3183 | // No credentials. |
| 3184 | MockRead(ASYNC, 1, |
| 3185 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3186 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3187 | "Proxy-Connection: keep-alive\r\n" |
| 3188 | "Content-Length: 10\r\n\r\n"), |
| 3189 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3190 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3191 | // Wrong credentials (wrong password). |
| 3192 | MockRead(ASYNC, 4, |
| 3193 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3194 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3195 | "Proxy-Connection: keep-alive\r\n" |
| 3196 | "Content-Length: 10\r\n\r\n"), |
| 3197 | // No response body because the test stops reading here. |
| 3198 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3199 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3200 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3201 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3202 | arraysize(data_writes1)); |
| 3203 | data1.set_busy_before_sync_reads(true); |
| 3204 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3205 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3206 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3207 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3208 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3209 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3210 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3211 | TestNetLogEntry::List entries; |
| 3212 | log.GetEntries(&entries); |
| 3213 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3214 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3215 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3216 | ExpectLogContainsSomewhere( |
| 3217 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3218 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3219 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3220 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3221 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3222 | ASSERT_TRUE(response); |
| 3223 | ASSERT_TRUE(response->headers); |
| 3224 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3225 | EXPECT_EQ(407, response->headers->response_code()); |
| 3226 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3227 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3228 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3229 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3230 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3231 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3232 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3233 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3234 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3235 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3236 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3237 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3238 | ASSERT_TRUE(response); |
| 3239 | ASSERT_TRUE(response->headers); |
| 3240 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3241 | EXPECT_EQ(407, response->headers->response_code()); |
| 3242 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3243 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3244 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3245 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3246 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3247 | // out of scope. |
| 3248 | session->CloseAllConnections(); |
| 3249 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3253 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3254 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3255 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3256 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3257 | // reused. See http://crbug.com/544255. |
| 3258 | for (int i = 0; i < 2; ++i) { |
| 3259 | HttpRequestInfo request; |
| 3260 | request.method = "GET"; |
| 3261 | request.url = GURL("https://www.example.org/"); |
| 3262 | // Ensure that proxy authentication is attempted even |
| 3263 | // when the no authentication data flag is set. |
| 3264 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3265 | |
| 3266 | // Configure against proxy server "myproxy:70". |
| 3267 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3268 | BoundTestNetLog log; |
| 3269 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3270 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3272 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3273 | |
| 3274 | // Since we have proxy, should try to establish tunnel. |
| 3275 | MockWrite data_writes1[] = { |
| 3276 | MockWrite(ASYNC, 0, |
| 3277 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3278 | "Host: www.example.org:443\r\n" |
| 3279 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3280 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3281 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3282 | // be issuing -- the final header line contains the credentials. |
| 3283 | MockWrite(ASYNC, 3, |
| 3284 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3285 | "Host: www.example.org:443\r\n" |
| 3286 | "Proxy-Connection: keep-alive\r\n" |
| 3287 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3288 | }; |
| 3289 | |
| 3290 | // The proxy responds to the connect with a 407, using a persistent |
| 3291 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3292 | MockRead data_reads1[] = { |
| 3293 | // No credentials. |
| 3294 | MockRead(ASYNC, 1, |
| 3295 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3296 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3297 | "Content-Length: 10\r\n\r\n"), |
| 3298 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3299 | |
| 3300 | // Wrong credentials (wrong password). |
| 3301 | MockRead(ASYNC, 4, |
| 3302 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3303 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3304 | "Content-Length: 10\r\n\r\n"), |
| 3305 | // No response body because the test stops reading here. |
| 3306 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3307 | }; |
| 3308 | |
| 3309 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3310 | arraysize(data_writes1)); |
| 3311 | data1.set_busy_before_sync_reads(true); |
| 3312 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3313 | |
| 3314 | TestCompletionCallback callback1; |
| 3315 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3316 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3317 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3318 | |
| 3319 | TestNetLogEntry::List entries; |
| 3320 | log.GetEntries(&entries); |
| 3321 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3322 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3323 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3324 | ExpectLogContainsSomewhere( |
| 3325 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3326 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3327 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3328 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3329 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3330 | ASSERT_TRUE(response); |
| 3331 | ASSERT_TRUE(response->headers); |
| 3332 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3333 | EXPECT_EQ(407, response->headers->response_code()); |
| 3334 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3335 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3336 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3337 | |
| 3338 | TestCompletionCallback callback2; |
| 3339 | |
| 3340 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3341 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3342 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3343 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3344 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3345 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3346 | ASSERT_TRUE(response); |
| 3347 | ASSERT_TRUE(response->headers); |
| 3348 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3349 | EXPECT_EQ(407, response->headers->response_code()); |
| 3350 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3351 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3352 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3353 | |
| 3354 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3355 | // out of scope. |
| 3356 | session->CloseAllConnections(); |
| 3357 | } |
| 3358 | } |
| 3359 | |
| 3360 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3361 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3362 | // the case the server sends extra data on the original socket, so it can't be |
| 3363 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3364 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3365 | HttpRequestInfo request; |
| 3366 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3367 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3368 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3369 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3370 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3371 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3372 | session_deps_.proxy_service = |
| 3373 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3374 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3375 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3376 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3377 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3378 | // Since we have proxy, should try to establish tunnel. |
| 3379 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3380 | MockWrite(ASYNC, 0, |
| 3381 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3382 | "Host: www.example.org:443\r\n" |
| 3383 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3384 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3385 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3386 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3387 | // extra data, so the socket cannot be reused. |
| 3388 | MockRead data_reads1[] = { |
| 3389 | // No credentials. |
| 3390 | MockRead(ASYNC, 1, |
| 3391 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3392 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3393 | "Content-Length: 10\r\n\r\n"), |
| 3394 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3395 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3396 | }; |
| 3397 | |
| 3398 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3399 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3400 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3401 | MockWrite(ASYNC, 0, |
| 3402 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3403 | "Host: www.example.org:443\r\n" |
| 3404 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3405 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3406 | |
| 3407 | MockWrite(ASYNC, 2, |
| 3408 | "GET / HTTP/1.1\r\n" |
| 3409 | "Host: www.example.org\r\n" |
| 3410 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3411 | }; |
| 3412 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3413 | MockRead data_reads2[] = { |
| 3414 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3415 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3416 | MockRead(ASYNC, 3, |
| 3417 | "HTTP/1.1 200 OK\r\n" |
| 3418 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3419 | "Content-Length: 5\r\n\r\n"), |
| 3420 | // No response body because the test stops reading here. |
| 3421 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3422 | }; |
| 3423 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3424 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3425 | arraysize(data_writes1)); |
| 3426 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3427 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3428 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3429 | arraysize(data_writes2)); |
| 3430 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3431 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3432 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3434 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3435 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3436 | auto trans = |
| 3437 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3438 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3439 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3440 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3441 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3442 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3443 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3444 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3445 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3446 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3447 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3448 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3449 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3450 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3451 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3452 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3453 | ASSERT_TRUE(response); |
| 3454 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3455 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3456 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3457 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3458 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3459 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3460 | LoadTimingInfo load_timing_info; |
| 3461 | // CONNECT requests and responses are handled at the connect job level, so |
| 3462 | // the transaction does not yet have a connection. |
| 3463 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3464 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3465 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3466 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3467 | rv = |
| 3468 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3469 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3470 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3471 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3472 | EXPECT_EQ(200, response->headers->response_code()); |
| 3473 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3474 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3475 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3476 | // The password prompt info should not be set. |
| 3477 | EXPECT_FALSE(response->auth_challenge); |
| 3478 | |
| 3479 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3480 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3481 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3482 | |
| 3483 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3484 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3485 | } |
| 3486 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3487 | // Test the case a proxy closes a socket while the challenge body is being |
| 3488 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3489 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3490 | HttpRequestInfo request; |
| 3491 | request.method = "GET"; |
| 3492 | request.url = GURL("https://www.example.org/"); |
| 3493 | // Ensure that proxy authentication is attempted even |
| 3494 | // when the no authentication data flag is set. |
| 3495 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3496 | |
| 3497 | // Configure against proxy server "myproxy:70". |
| 3498 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3499 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3500 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3501 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3502 | |
| 3503 | // Since we have proxy, should try to establish tunnel. |
| 3504 | MockWrite data_writes1[] = { |
| 3505 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3506 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3507 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3508 | }; |
| 3509 | |
| 3510 | // The proxy responds to the connect with a 407, using a persistent |
| 3511 | // connection. |
| 3512 | MockRead data_reads1[] = { |
| 3513 | // No credentials. |
| 3514 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3515 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3516 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3517 | // Server hands up in the middle of the body. |
| 3518 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3519 | }; |
| 3520 | |
| 3521 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3522 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3523 | // be issuing -- the final header line contains the credentials. |
| 3524 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3525 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3526 | "Proxy-Connection: keep-alive\r\n" |
| 3527 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3528 | |
| 3529 | MockWrite("GET / HTTP/1.1\r\n" |
| 3530 | "Host: www.example.org\r\n" |
| 3531 | "Connection: keep-alive\r\n\r\n"), |
| 3532 | }; |
| 3533 | |
| 3534 | MockRead data_reads2[] = { |
| 3535 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3536 | |
| 3537 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3538 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3539 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3540 | MockRead(SYNCHRONOUS, "hello"), |
| 3541 | }; |
| 3542 | |
| 3543 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3544 | data_writes1, arraysize(data_writes1)); |
| 3545 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3546 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3547 | data_writes2, arraysize(data_writes2)); |
| 3548 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3549 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3550 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3551 | |
| 3552 | TestCompletionCallback callback; |
| 3553 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3554 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3555 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3556 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3557 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3558 | ASSERT_TRUE(response); |
| 3559 | ASSERT_TRUE(response->headers); |
| 3560 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3561 | EXPECT_EQ(407, response->headers->response_code()); |
| 3562 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3563 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3564 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3565 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3566 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3567 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3568 | ASSERT_TRUE(response); |
| 3569 | ASSERT_TRUE(response->headers); |
| 3570 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3571 | EXPECT_EQ(200, response->headers->response_code()); |
| 3572 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3573 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3574 | EXPECT_EQ("hello", body); |
| 3575 | } |
| 3576 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3577 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3578 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3579 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3580 | HttpRequestInfo request; |
| 3581 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3582 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3583 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3584 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3585 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3586 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3587 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3588 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3589 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3590 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3591 | // Since we have proxy, should try to establish tunnel. |
| 3592 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3593 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3594 | "Host: www.example.org:443\r\n" |
| 3595 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3596 | }; |
| 3597 | |
| 3598 | // The proxy responds to the connect with a 407. |
| 3599 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3600 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3601 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3602 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3603 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3604 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3605 | }; |
| 3606 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3607 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3608 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3609 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3610 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3611 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3612 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3613 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3614 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3615 | |
| 3616 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3617 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3618 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3619 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3620 | ASSERT_TRUE(response); |
| 3621 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3622 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3623 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3624 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3625 | |
| 3626 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3627 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3628 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3629 | |
| 3630 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3631 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3632 | } |
| 3633 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3634 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3635 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3636 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3637 | HttpRequestInfo request; |
| 3638 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3639 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3640 | |
| 3641 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3642 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3643 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3644 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3645 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3646 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3647 | |
| 3648 | // Since we have proxy, should try to establish tunnel. |
| 3649 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3650 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3651 | "Host: www.example.org:443\r\n" |
| 3652 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3653 | }; |
| 3654 | |
| 3655 | // The proxy responds to the connect with a 407. |
| 3656 | MockRead data_reads[] = { |
| 3657 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3658 | MockRead("X-Foo: bar\r\n"), |
| 3659 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3660 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3661 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3662 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3663 | }; |
| 3664 | |
| 3665 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3666 | arraysize(data_writes)); |
| 3667 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3668 | |
| 3669 | TestCompletionCallback callback; |
| 3670 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3671 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3672 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3673 | |
| 3674 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3675 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3676 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3677 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3678 | ASSERT_TRUE(response); |
| 3679 | ASSERT_TRUE(response->headers); |
| 3680 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3681 | EXPECT_EQ(407, response->headers->response_code()); |
| 3682 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3683 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3684 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3685 | |
| 3686 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3687 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3688 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3689 | |
| 3690 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3691 | session->CloseAllConnections(); |
| 3692 | } |
| 3693 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3694 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3695 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3696 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3697 | HttpRequestInfo request; |
| 3698 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3699 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3700 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3701 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3702 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3703 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3704 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3705 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3706 | MockWrite( |
| 3707 | "GET / HTTP/1.1\r\n" |
| 3708 | "Host: www.example.org\r\n" |
| 3709 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3710 | }; |
| 3711 | |
| 3712 | MockRead data_reads1[] = { |
| 3713 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3714 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3715 | // Large content-length -- won't matter, as connection will be reset. |
| 3716 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3717 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3718 | }; |
| 3719 | |
| 3720 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3721 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3722 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3723 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3724 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3725 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3726 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3727 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3728 | |
| 3729 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3730 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3731 | } |
| 3732 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3733 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3734 | // through a non-authenticating proxy. The request should fail with |
| 3735 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3736 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3737 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3738 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3739 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3740 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3741 | HttpRequestInfo request; |
| 3742 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3743 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3744 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3745 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3746 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3747 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3748 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3749 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3750 | // Since we have proxy, should try to establish tunnel. |
| 3751 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3752 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3753 | "Host: www.example.org:443\r\n" |
| 3754 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3755 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3756 | MockWrite("GET / HTTP/1.1\r\n" |
| 3757 | "Host: www.example.org\r\n" |
| 3758 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3759 | }; |
| 3760 | |
| 3761 | MockRead data_reads1[] = { |
| 3762 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3763 | |
| 3764 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3765 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3766 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3767 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3768 | }; |
| 3769 | |
| 3770 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3771 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3772 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3773 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3774 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3775 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3776 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3777 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3778 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3779 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3780 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3781 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3782 | |
| 3783 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3784 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3785 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3786 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3787 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3788 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3789 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3790 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3791 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3792 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3793 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3794 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3795 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3796 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3797 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3798 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3799 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3800 | HttpRequestInfo request; |
| 3801 | request.method = "GET"; |
| 3802 | request.url = GURL("https://www.example.org/"); |
| 3803 | |
| 3804 | // Configure against proxy server "myproxy:70". |
| 3805 | session_deps_.proxy_service = |
| 3806 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3807 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3808 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3809 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3810 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3811 | mock_handler->set_allows_default_credentials(true); |
| 3812 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3813 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3814 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3815 | |
| 3816 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3817 | NetLog net_log; |
| 3818 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3819 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3820 | |
| 3821 | // Since we have proxy, should try to establish tunnel. |
| 3822 | MockWrite data_writes1[] = { |
| 3823 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3824 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3825 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3826 | }; |
| 3827 | |
| 3828 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3829 | // connection. |
| 3830 | MockRead data_reads1[] = { |
| 3831 | // No credentials. |
| 3832 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3833 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3834 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3835 | }; |
| 3836 | |
| 3837 | // Since the first connection couldn't be reused, need to establish another |
| 3838 | // once given credentials. |
| 3839 | MockWrite data_writes2[] = { |
| 3840 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3841 | // be issuing -- the final header line contains the credentials. |
| 3842 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3843 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3844 | "Proxy-Connection: keep-alive\r\n" |
| 3845 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3846 | |
| 3847 | MockWrite("GET / HTTP/1.1\r\n" |
| 3848 | "Host: www.example.org\r\n" |
| 3849 | "Connection: keep-alive\r\n\r\n"), |
| 3850 | }; |
| 3851 | |
| 3852 | MockRead data_reads2[] = { |
| 3853 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3854 | |
| 3855 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3856 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3857 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3858 | MockRead(SYNCHRONOUS, "hello"), |
| 3859 | }; |
| 3860 | |
| 3861 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3862 | data_writes1, arraysize(data_writes1)); |
| 3863 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3864 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3865 | data_writes2, arraysize(data_writes2)); |
| 3866 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3867 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3868 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3869 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3870 | auto trans = |
| 3871 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3872 | |
| 3873 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3874 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3875 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3876 | |
| 3877 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3878 | ASSERT_TRUE(response); |
| 3879 | ASSERT_TRUE(response->headers); |
| 3880 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3881 | EXPECT_EQ(407, response->headers->response_code()); |
| 3882 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3883 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3884 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3885 | |
| 3886 | LoadTimingInfo load_timing_info; |
| 3887 | // CONNECT requests and responses are handled at the connect job level, so |
| 3888 | // the transaction does not yet have a connection. |
| 3889 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3890 | |
| 3891 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3892 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3893 | response = trans->GetResponseInfo(); |
| 3894 | ASSERT_TRUE(response); |
| 3895 | ASSERT_TRUE(response->headers); |
| 3896 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3897 | EXPECT_EQ(200, response->headers->response_code()); |
| 3898 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3899 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3900 | |
| 3901 | // The password prompt info should not be set. |
| 3902 | EXPECT_FALSE(response->auth_challenge); |
| 3903 | |
| 3904 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3905 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3906 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3907 | |
| 3908 | trans.reset(); |
| 3909 | session->CloseAllConnections(); |
| 3910 | } |
| 3911 | |
| 3912 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3913 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3914 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3915 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3916 | HttpRequestInfo request; |
| 3917 | request.method = "GET"; |
| 3918 | request.url = GURL("https://www.example.org/"); |
| 3919 | |
| 3920 | // Configure against proxy server "myproxy:70". |
| 3921 | session_deps_.proxy_service = |
| 3922 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3923 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3924 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3925 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3926 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3927 | mock_handler->set_allows_default_credentials(true); |
| 3928 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3929 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3930 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3931 | |
| 3932 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3933 | NetLog net_log; |
| 3934 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3935 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3936 | |
| 3937 | // Should try to establish tunnel. |
| 3938 | MockWrite data_writes1[] = { |
| 3939 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3940 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3941 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3942 | |
| 3943 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3944 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3945 | "Proxy-Connection: keep-alive\r\n" |
| 3946 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3947 | }; |
| 3948 | |
| 3949 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3950 | // connection. |
| 3951 | MockRead data_reads1[] = { |
| 3952 | // No credentials. |
| 3953 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3954 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3955 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3956 | }; |
| 3957 | |
| 3958 | // Since the first connection was closed, need to establish another once given |
| 3959 | // credentials. |
| 3960 | MockWrite data_writes2[] = { |
| 3961 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3962 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3963 | "Proxy-Connection: keep-alive\r\n" |
| 3964 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3965 | |
| 3966 | MockWrite("GET / HTTP/1.1\r\n" |
| 3967 | "Host: www.example.org\r\n" |
| 3968 | "Connection: keep-alive\r\n\r\n"), |
| 3969 | }; |
| 3970 | |
| 3971 | MockRead data_reads2[] = { |
| 3972 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3973 | |
| 3974 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3975 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3976 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3977 | MockRead(SYNCHRONOUS, "hello"), |
| 3978 | }; |
| 3979 | |
| 3980 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3981 | data_writes1, arraysize(data_writes1)); |
| 3982 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3983 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3984 | data_writes2, arraysize(data_writes2)); |
| 3985 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3986 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3987 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3988 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3989 | auto trans = |
| 3990 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3991 | |
| 3992 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3993 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3994 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3995 | |
| 3996 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3997 | ASSERT_TRUE(response); |
| 3998 | ASSERT_TRUE(response->headers); |
| 3999 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4000 | EXPECT_EQ(407, response->headers->response_code()); |
| 4001 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4002 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4003 | EXPECT_FALSE(response->auth_challenge); |
| 4004 | |
| 4005 | LoadTimingInfo load_timing_info; |
| 4006 | // CONNECT requests and responses are handled at the connect job level, so |
| 4007 | // the transaction does not yet have a connection. |
| 4008 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4009 | |
| 4010 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4011 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4012 | |
| 4013 | response = trans->GetResponseInfo(); |
| 4014 | ASSERT_TRUE(response); |
| 4015 | ASSERT_TRUE(response->headers); |
| 4016 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4017 | EXPECT_EQ(200, response->headers->response_code()); |
| 4018 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4019 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4020 | |
| 4021 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4022 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4023 | |
| 4024 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4025 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4026 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4027 | |
| 4028 | trans.reset(); |
| 4029 | session->CloseAllConnections(); |
| 4030 | } |
| 4031 | |
| 4032 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4033 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4034 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4035 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4036 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4037 | HttpRequestInfo request; |
| 4038 | request.method = "GET"; |
| 4039 | request.url = GURL("https://www.example.org/"); |
| 4040 | |
| 4041 | // Configure against proxy server "myproxy:70". |
| 4042 | session_deps_.proxy_service = |
| 4043 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4044 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4045 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4046 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4047 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4048 | mock_handler->set_allows_default_credentials(true); |
| 4049 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4050 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4051 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4052 | |
| 4053 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4054 | NetLog net_log; |
| 4055 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4056 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4057 | |
| 4058 | // Should try to establish tunnel. |
| 4059 | MockWrite data_writes1[] = { |
| 4060 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4061 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4062 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4063 | |
| 4064 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4065 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4066 | "Proxy-Connection: keep-alive\r\n" |
| 4067 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4068 | }; |
| 4069 | |
| 4070 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4071 | // second request is sent. |
| 4072 | MockRead data_reads1[] = { |
| 4073 | // No credentials. |
| 4074 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4075 | MockRead("Content-Length: 0\r\n"), |
| 4076 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4077 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4078 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4079 | }; |
| 4080 | |
| 4081 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4082 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4083 | // request. |
| 4084 | MockWrite data_writes2[] = { |
| 4085 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4086 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4087 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4088 | }; |
| 4089 | |
| 4090 | // The proxy, having had more than enough of us, just hangs up. |
| 4091 | MockRead data_reads2[] = { |
| 4092 | // No credentials. |
| 4093 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4094 | }; |
| 4095 | |
| 4096 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4097 | data_writes1, arraysize(data_writes1)); |
| 4098 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4099 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4100 | data_writes2, arraysize(data_writes2)); |
| 4101 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4102 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4103 | auto trans = |
| 4104 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4105 | |
| 4106 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4107 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4108 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4109 | |
| 4110 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4111 | ASSERT_TRUE(response); |
| 4112 | ASSERT_TRUE(response->headers); |
| 4113 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4114 | EXPECT_EQ(407, response->headers->response_code()); |
| 4115 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4116 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4117 | EXPECT_FALSE(response->auth_challenge); |
| 4118 | |
| 4119 | LoadTimingInfo load_timing_info; |
| 4120 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4121 | |
| 4122 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4123 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4124 | |
| 4125 | trans.reset(); |
| 4126 | session->CloseAllConnections(); |
| 4127 | } |
| 4128 | |
| 4129 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4130 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4131 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4132 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4133 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4134 | HttpRequestInfo request; |
| 4135 | request.method = "GET"; |
| 4136 | request.url = GURL("https://www.example.org/"); |
| 4137 | |
| 4138 | // Configure against proxy server "myproxy:70". |
| 4139 | session_deps_.proxy_service = |
| 4140 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4141 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4142 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4143 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4144 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4145 | mock_handler->set_allows_default_credentials(true); |
| 4146 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4147 | HttpAuth::AUTH_PROXY); |
| 4148 | // Add another handler for the second challenge. It supports default |
| 4149 | // credentials, but they shouldn't be used, since they were already tried. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4150 | mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4151 | mock_handler->set_allows_default_credentials(true); |
| 4152 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4153 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4154 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4155 | |
| 4156 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4157 | NetLog net_log; |
| 4158 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4159 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4160 | |
| 4161 | // Should try to establish tunnel. |
| 4162 | MockWrite data_writes1[] = { |
| 4163 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4164 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4165 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4166 | }; |
| 4167 | |
| 4168 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4169 | // connection. |
| 4170 | MockRead data_reads1[] = { |
| 4171 | // No credentials. |
| 4172 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4173 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4174 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4175 | }; |
| 4176 | |
| 4177 | // Since the first connection was closed, need to establish another once given |
| 4178 | // credentials. |
| 4179 | MockWrite data_writes2[] = { |
| 4180 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4181 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4182 | "Proxy-Connection: keep-alive\r\n" |
| 4183 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4184 | }; |
| 4185 | |
| 4186 | MockRead data_reads2[] = { |
| 4187 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4188 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4189 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4190 | }; |
| 4191 | |
| 4192 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4193 | data_writes1, arraysize(data_writes1)); |
| 4194 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4195 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4196 | data_writes2, arraysize(data_writes2)); |
| 4197 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4198 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4199 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4200 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4201 | auto trans = |
| 4202 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4203 | |
| 4204 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4205 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4206 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4207 | |
| 4208 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4209 | ASSERT_TRUE(response); |
| 4210 | ASSERT_TRUE(response->headers); |
| 4211 | EXPECT_EQ(407, response->headers->response_code()); |
| 4212 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4213 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4214 | EXPECT_FALSE(response->auth_challenge); |
| 4215 | |
| 4216 | LoadTimingInfo load_timing_info; |
| 4217 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4218 | |
| 4219 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4220 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4221 | response = trans->GetResponseInfo(); |
| 4222 | ASSERT_TRUE(response); |
| 4223 | ASSERT_TRUE(response->headers); |
| 4224 | EXPECT_EQ(407, response->headers->response_code()); |
| 4225 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4226 | EXPECT_TRUE(response->auth_challenge); |
| 4227 | |
| 4228 | trans.reset(); |
| 4229 | session->CloseAllConnections(); |
| 4230 | } |
| 4231 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4232 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4233 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4234 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4235 | // authentication handshake can continue with the same scheme but with a |
| 4236 | // different identity. |
| 4237 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4238 | HttpRequestInfo request; |
| 4239 | request.method = "GET"; |
| 4240 | request.url = GURL("http://www.example.org/"); |
| 4241 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4242 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4243 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4244 | |
| 4245 | // First handler. Uses default credentials, but barfs at generate auth token. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4246 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4247 | mock_handler->set_allows_default_credentials(true); |
| 4248 | mock_handler->set_allows_explicit_credentials(true); |
| 4249 | mock_handler->set_connection_based(true); |
| 4250 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4251 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4252 | HttpAuth::AUTH_SERVER); |
| 4253 | |
| 4254 | // Add another handler for the second challenge. It supports default |
| 4255 | // credentials, but they shouldn't be used, since they were already tried. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4256 | mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4257 | mock_handler->set_allows_default_credentials(true); |
| 4258 | mock_handler->set_allows_explicit_credentials(true); |
| 4259 | mock_handler->set_connection_based(true); |
| 4260 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4261 | HttpAuth::AUTH_SERVER); |
| 4262 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4263 | |
| 4264 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4265 | |
| 4266 | MockWrite data_writes1[] = { |
| 4267 | MockWrite("GET / HTTP/1.1\r\n" |
| 4268 | "Host: www.example.org\r\n" |
| 4269 | "Connection: keep-alive\r\n\r\n"), |
| 4270 | }; |
| 4271 | |
| 4272 | MockRead data_reads1[] = { |
| 4273 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4274 | "WWW-Authenticate: Mock\r\n" |
| 4275 | "Connection: keep-alive\r\n\r\n"), |
| 4276 | }; |
| 4277 | |
| 4278 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4279 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4280 | // transaction procceds without an authorization header. |
| 4281 | MockWrite data_writes2[] = { |
| 4282 | MockWrite("GET / HTTP/1.1\r\n" |
| 4283 | "Host: www.example.org\r\n" |
| 4284 | "Connection: keep-alive\r\n\r\n"), |
| 4285 | }; |
| 4286 | |
| 4287 | MockRead data_reads2[] = { |
| 4288 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4289 | "WWW-Authenticate: Mock\r\n" |
| 4290 | "Connection: keep-alive\r\n\r\n"), |
| 4291 | }; |
| 4292 | |
| 4293 | MockWrite data_writes3[] = { |
| 4294 | MockWrite("GET / HTTP/1.1\r\n" |
| 4295 | "Host: www.example.org\r\n" |
| 4296 | "Connection: keep-alive\r\n" |
| 4297 | "Authorization: auth_token\r\n\r\n"), |
| 4298 | }; |
| 4299 | |
| 4300 | MockRead data_reads3[] = { |
| 4301 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4302 | "Content-Length: 5\r\n" |
| 4303 | "Content-Type: text/plain\r\n" |
| 4304 | "Connection: keep-alive\r\n\r\n" |
| 4305 | "Hello"), |
| 4306 | }; |
| 4307 | |
| 4308 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4309 | data_writes1, arraysize(data_writes1)); |
| 4310 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4311 | |
| 4312 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4313 | data_writes2, arraysize(data_writes2)); |
| 4314 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4315 | |
| 4316 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4317 | data_writes3, arraysize(data_writes3)); |
| 4318 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4319 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4320 | auto trans = |
| 4321 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4322 | |
| 4323 | TestCompletionCallback callback; |
| 4324 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4325 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4326 | |
| 4327 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4328 | ASSERT_TRUE(response); |
| 4329 | ASSERT_TRUE(response->headers); |
| 4330 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4331 | |
| 4332 | // The following three tests assert that an authentication challenge was |
| 4333 | // received and that the stack is ready to respond to the challenge using |
| 4334 | // ambient credentials. |
| 4335 | EXPECT_EQ(401, response->headers->response_code()); |
| 4336 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4337 | EXPECT_FALSE(response->auth_challenge); |
| 4338 | |
| 4339 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4340 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4341 | response = trans->GetResponseInfo(); |
| 4342 | ASSERT_TRUE(response); |
| 4343 | ASSERT_TRUE(response->headers); |
| 4344 | |
| 4345 | // The following three tests assert that an authentication challenge was |
| 4346 | // received and that the stack needs explicit credentials before it is ready |
| 4347 | // to respond to the challenge. |
| 4348 | EXPECT_EQ(401, response->headers->response_code()); |
| 4349 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4350 | EXPECT_TRUE(response->auth_challenge); |
| 4351 | |
| 4352 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4353 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4354 | response = trans->GetResponseInfo(); |
| 4355 | ASSERT_TRUE(response); |
| 4356 | ASSERT_TRUE(response->headers); |
| 4357 | EXPECT_EQ(200, response->headers->response_code()); |
| 4358 | |
| 4359 | trans.reset(); |
| 4360 | session->CloseAllConnections(); |
| 4361 | } |
| 4362 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4363 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4364 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4365 | HttpRequestInfo request1; |
| 4366 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4367 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4368 | |
| 4369 | HttpRequestInfo request2; |
| 4370 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4371 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4372 | |
| 4373 | // Configure against proxy server "myproxy:70". |
brettw | c1213d9 | 2016-11-12 03:41:13 | [diff] [blame] | 4374 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4375 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4376 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4377 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4378 | |
| 4379 | // Since we have proxy, should try to establish tunnel. |
| 4380 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4381 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4382 | "Host: www.example.org:443\r\n" |
| 4383 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4384 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4385 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4386 | "Host: www.example.org\r\n" |
| 4387 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4388 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4389 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4390 | "Host: www.example.org\r\n" |
| 4391 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4392 | }; |
| 4393 | |
| 4394 | // The proxy responds to the connect with a 407, using a persistent |
| 4395 | // connection. |
| 4396 | MockRead data_reads1[] = { |
| 4397 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4398 | |
| 4399 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4400 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4401 | MockRead(SYNCHRONOUS, "1"), |
| 4402 | |
| 4403 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4404 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4405 | MockRead(SYNCHRONOUS, "22"), |
| 4406 | }; |
| 4407 | |
| 4408 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4409 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4410 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4411 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4412 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4413 | |
| 4414 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4415 | auto trans1 = |
| 4416 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4417 | |
| 4418 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4419 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4420 | |
| 4421 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4422 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4423 | |
| 4424 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4425 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4426 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4427 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4428 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4429 | |
| 4430 | LoadTimingInfo load_timing_info1; |
| 4431 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4432 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4433 | |
| 4434 | trans1.reset(); |
| 4435 | |
| 4436 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4437 | auto trans2 = |
| 4438 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4439 | |
| 4440 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4441 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4442 | |
| 4443 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4444 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4445 | |
| 4446 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4447 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4448 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4449 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4450 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4451 | |
| 4452 | LoadTimingInfo load_timing_info2; |
| 4453 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4454 | TestLoadTimingReused(load_timing_info2); |
| 4455 | |
| 4456 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4457 | |
| 4458 | trans2.reset(); |
| 4459 | session->CloseAllConnections(); |
| 4460 | } |
| 4461 | |
| 4462 | // 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] | 4463 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4464 | HttpRequestInfo request1; |
| 4465 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4466 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4467 | |
| 4468 | HttpRequestInfo request2; |
| 4469 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4470 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4471 | |
| 4472 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4473 | session_deps_.proxy_service = |
| 4474 | ProxyService::CreateFixedFromPacResult("PROXY 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 = |
| 4516 | base::MakeUnique<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); |
| 4526 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4527 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4528 | |
| 4529 | LoadTimingInfo load_timing_info1; |
| 4530 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4531 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4532 | 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 = |
| 4538 | base::MakeUnique<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); |
| 4548 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4549 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4550 | |
| 4551 | LoadTimingInfo load_timing_info2; |
| 4552 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4553 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4554 | |
| 4555 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4556 | |
| 4557 | trans2.reset(); |
| 4558 | session->CloseAllConnections(); |
| 4559 | } |
| 4560 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4561 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4562 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4563 | HttpRequestInfo request; |
| 4564 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4565 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4566 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4567 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4568 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4569 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4570 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4571 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4572 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4573 | // Since we have proxy, should use full url |
| 4574 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4575 | MockWrite( |
| 4576 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4577 | "Host: www.example.org\r\n" |
| 4578 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4579 | }; |
| 4580 | |
| 4581 | MockRead data_reads1[] = { |
| 4582 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4583 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4584 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4585 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4586 | }; |
| 4587 | |
| 4588 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4589 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4590 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4591 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4592 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4593 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4594 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4595 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4596 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4597 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4598 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4599 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4600 | |
| 4601 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4602 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4603 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4604 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4605 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4606 | TestLoadTimingNotReused(load_timing_info, |
| 4607 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4608 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4609 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4610 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4611 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4612 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4613 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4614 | EXPECT_EQ(200, response->headers->response_code()); |
| 4615 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4616 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4617 | |
| 4618 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4619 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4620 | } |
| 4621 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4622 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4623 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4624 | HttpRequestInfo request; |
| 4625 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4626 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4627 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4628 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4629 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4630 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4631 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4632 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4633 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4634 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4635 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4636 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4637 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4638 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4639 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4640 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4641 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4642 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4643 | }; |
| 4644 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4645 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4646 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4647 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4648 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4649 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4650 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4651 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4652 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4653 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4654 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4656 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4657 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4658 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4659 | |
| 4660 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4661 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4662 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4663 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4664 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4665 | TestLoadTimingNotReused(load_timing_info, |
| 4666 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4667 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4668 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4669 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4670 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4671 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4672 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4673 | |
| 4674 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4675 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4676 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4677 | } |
| 4678 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4679 | // Verifies that a session which races and wins against the owning transaction |
| 4680 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4681 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4682 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4683 | HttpRequestInfo request; |
| 4684 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4685 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4686 | |
| 4687 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4688 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4689 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4690 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4691 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4692 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4693 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4694 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4695 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4696 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4697 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4698 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4699 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4700 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4701 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4702 | }; |
| 4703 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4704 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4705 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4706 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4707 | |
| 4708 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4709 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4710 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4711 | |
| 4712 | TestCompletionCallback callback1; |
| 4713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4714 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4715 | |
| 4716 | // Stall the hostname resolution begun by the transaction. |
| 4717 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4718 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4720 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4721 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4722 | |
| 4723 | // Race a session to the proxy, which completes first. |
| 4724 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4725 | SpdySessionKey key( |
| 4726 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4727 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4728 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4729 | |
| 4730 | // Unstall the resolution begun by the transaction. |
| 4731 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4732 | session_deps_.host_resolver->ResolveAllPending(); |
| 4733 | |
| 4734 | EXPECT_FALSE(callback1.have_result()); |
| 4735 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4736 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4738 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4739 | ASSERT_TRUE(response); |
| 4740 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4741 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4742 | |
| 4743 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4744 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4745 | EXPECT_EQ(kUploadData, response_data); |
| 4746 | } |
| 4747 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4748 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4749 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4750 | HttpRequestInfo request; |
| 4751 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4752 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4753 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4754 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4755 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4756 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4757 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4759 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4760 | // The first request will be a bare GET, the second request will be a |
| 4761 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4762 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4763 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4764 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4765 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4766 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4767 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4768 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4769 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4770 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4771 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4772 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4773 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4774 | }; |
| 4775 | |
| 4776 | // The first response is a 407 proxy authentication challenge, and the second |
| 4777 | // response will be a 200 response since the second request includes a valid |
| 4778 | // Authorization header. |
| 4779 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4780 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4781 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4782 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 4783 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4784 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4785 | SpdySerializedFrame body_authentication( |
| 4786 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4787 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4788 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4789 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4790 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 4791 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4792 | CreateMockRead(resp_data, 4), |
| 4793 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4794 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4795 | }; |
| 4796 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4797 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4798 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4799 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4800 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4801 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4802 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4803 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4805 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4806 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4807 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4808 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4809 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4810 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4811 | |
| 4812 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4813 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4814 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4815 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4816 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4817 | ASSERT_TRUE(response); |
| 4818 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4819 | EXPECT_EQ(407, response->headers->response_code()); |
| 4820 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 4821 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4823 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4824 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4825 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4827 | |
| 4828 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4829 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4831 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4832 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4833 | ASSERT_TRUE(response_restart); |
| 4834 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4835 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4836 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4837 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4838 | } |
| 4839 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4840 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4841 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4842 | HttpRequestInfo request; |
| 4843 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4844 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4845 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4846 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4847 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4848 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4849 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4852 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4853 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4854 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4855 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4856 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4857 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4858 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4859 | const char get[] = |
| 4860 | "GET / HTTP/1.1\r\n" |
| 4861 | "Host: www.example.org\r\n" |
| 4862 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4863 | SpdySerializedFrame wrapped_get( |
| 4864 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4865 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4866 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4867 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4868 | SpdySerializedFrame wrapped_get_resp( |
| 4869 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 4870 | SpdySerializedFrame wrapped_body( |
| 4871 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 4872 | SpdySerializedFrame window_update( |
| 4873 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4874 | |
| 4875 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4876 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4877 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4878 | }; |
| 4879 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4880 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4881 | CreateMockRead(conn_resp, 1, ASYNC), |
| 4882 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 4883 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 4884 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4885 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4886 | }; |
| 4887 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4888 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4889 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4890 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4891 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4892 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4893 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4894 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4895 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4896 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4898 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4899 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4900 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4902 | |
| 4903 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4904 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4905 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4906 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4907 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4908 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4909 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4910 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4911 | ASSERT_TRUE(response); |
| 4912 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4913 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4914 | |
| 4915 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4916 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4917 | EXPECT_EQ("1234567890", response_data); |
| 4918 | } |
| 4919 | |
| 4920 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4921 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 4922 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4923 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4924 | HttpRequestInfo request; |
| 4925 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4926 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4927 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4928 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4929 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4930 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4931 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4932 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4933 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4934 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4935 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4936 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4937 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4938 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4939 | // fetch https://www.example.org/ via SPDY |
| 4940 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4941 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4942 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4943 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4944 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4945 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4946 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4947 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4948 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4949 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 4950 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4951 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4952 | SpdySerializedFrame window_update_get_resp( |
| 4953 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 4954 | SpdySerializedFrame window_update_body( |
| 4955 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4956 | |
| 4957 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4958 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4959 | CreateMockWrite(window_update_get_resp, 6), |
| 4960 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4961 | }; |
| 4962 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4963 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4964 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4965 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4966 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 4967 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4968 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4969 | }; |
| 4970 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4971 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4972 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4973 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4974 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4975 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4976 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4977 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4978 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4979 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4980 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4982 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4983 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4984 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4985 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4986 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4987 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 4988 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4989 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4990 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4991 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4992 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4993 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4994 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4995 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4996 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4998 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4999 | ASSERT_TRUE(response); |
| 5000 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5001 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5002 | |
| 5003 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5004 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5005 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5006 | } |
| 5007 | |
| 5008 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5009 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5010 | HttpRequestInfo request; |
| 5011 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5012 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5013 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5014 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5015 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5016 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5017 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5018 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5019 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5020 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5021 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5022 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5023 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5024 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5025 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5026 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5027 | |
| 5028 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5029 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5030 | }; |
| 5031 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5032 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5033 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5034 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5035 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5036 | }; |
| 5037 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5038 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5039 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5040 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5041 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5042 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5043 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5044 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5045 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5046 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5047 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5048 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5049 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5050 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5051 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5052 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5053 | |
| 5054 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5055 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5056 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5057 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5058 | } |
| 5059 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5060 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5061 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5062 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5063 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5064 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5065 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5066 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5067 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5068 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5069 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5070 | |
| 5071 | HttpRequestInfo request1; |
| 5072 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5073 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5074 | request1.load_flags = 0; |
| 5075 | |
| 5076 | HttpRequestInfo request2; |
| 5077 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5078 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5079 | request2.load_flags = 0; |
| 5080 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5081 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5082 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5083 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5084 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5085 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5086 | // Fetch https://www.example.org/ via HTTP. |
| 5087 | const char get1[] = |
| 5088 | "GET / HTTP/1.1\r\n" |
| 5089 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5090 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5091 | SpdySerializedFrame wrapped_get1( |
| 5092 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5093 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5094 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5095 | SpdySerializedFrame wrapped_get_resp1( |
| 5096 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5097 | SpdySerializedFrame wrapped_body1( |
| 5098 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5099 | SpdySerializedFrame window_update( |
| 5100 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5101 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5102 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5103 | SpdyHeaderBlock connect2_block; |
| 5104 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 5105 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5106 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5107 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5108 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5109 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5110 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5111 | // Fetch https://mail.example.org/ via HTTP. |
| 5112 | const char get2[] = |
| 5113 | "GET / HTTP/1.1\r\n" |
| 5114 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5115 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5116 | SpdySerializedFrame wrapped_get2( |
| 5117 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5118 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5119 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5120 | SpdySerializedFrame wrapped_get_resp2( |
| 5121 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5122 | SpdySerializedFrame wrapped_body2( |
| 5123 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5124 | |
| 5125 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5126 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5127 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5128 | }; |
| 5129 | |
| 5130 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5131 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5132 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5133 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5134 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5135 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5136 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5137 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5138 | }; |
| 5139 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5140 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5141 | arraysize(spdy_writes)); |
| 5142 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5143 | |
| 5144 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5145 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5146 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5147 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5148 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5149 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5150 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5151 | |
| 5152 | TestCompletionCallback callback; |
| 5153 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5154 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5155 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5156 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5157 | |
| 5158 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5159 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5160 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5161 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5162 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5163 | ASSERT_TRUE(response); |
| 5164 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5165 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5166 | |
| 5167 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5168 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5169 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5170 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5172 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5173 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5174 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5175 | |
| 5176 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5177 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5178 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5179 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5180 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5181 | |
| 5182 | // The requests should have different IDs, since they each are using their own |
| 5183 | // separate stream. |
| 5184 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5186 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5187 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5191 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5192 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5193 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5194 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5195 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5196 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5197 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5198 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5199 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5200 | |
| 5201 | HttpRequestInfo request1; |
| 5202 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5203 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5204 | request1.load_flags = 0; |
| 5205 | |
| 5206 | HttpRequestInfo request2; |
| 5207 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5208 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5209 | request2.load_flags = 0; |
| 5210 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5211 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5212 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5213 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5214 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5215 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5216 | // Fetch https://www.example.org/ via HTTP. |
| 5217 | const char get1[] = |
| 5218 | "GET / HTTP/1.1\r\n" |
| 5219 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5220 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5221 | SpdySerializedFrame wrapped_get1( |
| 5222 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5223 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5224 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5225 | SpdySerializedFrame wrapped_get_resp1( |
| 5226 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5227 | SpdySerializedFrame wrapped_body1( |
| 5228 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5229 | SpdySerializedFrame window_update( |
| 5230 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5231 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5232 | // Fetch https://www.example.org/2 via HTTP. |
| 5233 | const char get2[] = |
| 5234 | "GET /2 HTTP/1.1\r\n" |
| 5235 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5236 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5237 | SpdySerializedFrame wrapped_get2( |
| 5238 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5239 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5240 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5241 | SpdySerializedFrame wrapped_get_resp2( |
| 5242 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5243 | SpdySerializedFrame wrapped_body2( |
| 5244 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5245 | |
| 5246 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5247 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5248 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5249 | }; |
| 5250 | |
| 5251 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5252 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5253 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5254 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5255 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5256 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5257 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5258 | }; |
| 5259 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5260 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5261 | arraysize(spdy_writes)); |
| 5262 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5263 | |
| 5264 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5265 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5266 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5267 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5268 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5269 | |
| 5270 | TestCompletionCallback callback; |
| 5271 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5272 | auto trans = |
| 5273 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5274 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5275 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5276 | |
| 5277 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5278 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5279 | |
| 5280 | LoadTimingInfo load_timing_info; |
| 5281 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5282 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5283 | |
| 5284 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5285 | ASSERT_TRUE(response); |
| 5286 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5287 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5288 | |
| 5289 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5290 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5291 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5292 | trans.reset(); |
| 5293 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5294 | auto trans2 = |
| 5295 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5296 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5297 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5298 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5299 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5300 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5301 | |
| 5302 | LoadTimingInfo load_timing_info2; |
| 5303 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5304 | TestLoadTimingReused(load_timing_info2); |
| 5305 | |
| 5306 | // The requests should have the same ID. |
| 5307 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5308 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5309 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5313 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5314 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5315 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5316 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5317 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5318 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5319 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5320 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5321 | |
| 5322 | HttpRequestInfo request1; |
| 5323 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5324 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5325 | request1.load_flags = 0; |
| 5326 | |
| 5327 | HttpRequestInfo request2; |
| 5328 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5329 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5330 | request2.load_flags = 0; |
| 5331 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5332 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5333 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5334 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5335 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5336 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5337 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5338 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5339 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5340 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5341 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5342 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5343 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5344 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5345 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5346 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5347 | SpdySerializedFrame body2( |
| 5348 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5349 | |
| 5350 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5351 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5352 | }; |
| 5353 | |
| 5354 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5355 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5356 | CreateMockRead(body1, 2, ASYNC), |
| 5357 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5358 | CreateMockRead(body2, 5, ASYNC), |
| 5359 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5360 | }; |
| 5361 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5362 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5363 | arraysize(spdy_writes)); |
| 5364 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5365 | |
| 5366 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5367 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5368 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[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 = |
| 5373 | base::MakeUnique<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(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5376 | |
| 5377 | LoadTimingInfo load_timing_info; |
| 5378 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5379 | TestLoadTimingNotReused(load_timing_info, |
| 5380 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5381 | |
| 5382 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5383 | ASSERT_TRUE(response); |
| 5384 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5385 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5386 | |
| 5387 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5388 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5389 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5390 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5391 | // Delete the first request, so the second one can reuse the socket. |
| 5392 | trans.reset(); |
| 5393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5394 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5395 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5396 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5397 | |
| 5398 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5399 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5400 | TestLoadTimingReused(load_timing_info2); |
| 5401 | |
| 5402 | // The requests should have the same ID. |
| 5403 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5404 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5405 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5406 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5407 | } |
| 5408 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5409 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5410 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5411 | HttpRequestInfo request; |
| 5412 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5413 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5414 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5415 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5416 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5417 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5418 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5419 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5420 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5422 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5423 | // Since we have proxy, should use full url |
| 5424 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5425 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5426 | "Host: www.example.org\r\n" |
| 5427 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5428 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5429 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5430 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5431 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5432 | "Host: www.example.org\r\n" |
| 5433 | "Proxy-Connection: keep-alive\r\n" |
| 5434 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5435 | }; |
| 5436 | |
| 5437 | // The proxy responds to the GET with a 407, using a persistent |
| 5438 | // connection. |
| 5439 | MockRead data_reads1[] = { |
| 5440 | // No credentials. |
| 5441 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5442 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5443 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5444 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5445 | |
| 5446 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5447 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5448 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5449 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5450 | }; |
| 5451 | |
| 5452 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5453 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5454 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5455 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5456 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5457 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5458 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5459 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5460 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5462 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5464 | |
| 5465 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5466 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5467 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5468 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5469 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5470 | TestLoadTimingNotReused(load_timing_info, |
| 5471 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5472 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5473 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5474 | ASSERT_TRUE(response); |
| 5475 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5476 | EXPECT_EQ(407, response->headers->response_code()); |
| 5477 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5478 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5480 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5482 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5483 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5484 | |
| 5485 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5486 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5487 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5488 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5489 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5490 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5491 | TestLoadTimingReused(load_timing_info); |
| 5492 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5493 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5494 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5495 | |
| 5496 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5497 | EXPECT_EQ(200, response->headers->response_code()); |
| 5498 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5499 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5500 | |
| 5501 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5502 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5503 | } |
| 5504 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5505 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5506 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5507 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5508 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5509 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5510 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5511 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5512 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5513 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5514 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5515 | // Since we have proxy, should try to establish tunnel. |
| 5516 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5517 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5518 | "Host: www.example.org:443\r\n" |
| 5519 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5520 | }; |
| 5521 | |
| 5522 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5523 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5524 | // No response body because the test stops reading here. |
| 5525 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5526 | }; |
| 5527 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5528 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5529 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5530 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5531 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5532 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5534 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5535 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5536 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5537 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5538 | |
| 5539 | rv = callback.WaitForResult(); |
| 5540 | EXPECT_EQ(expected_status, rv); |
| 5541 | } |
| 5542 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5543 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5544 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5545 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5546 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5547 | } |
| 5548 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5549 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5550 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5551 | } |
| 5552 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5553 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5554 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5555 | } |
| 5556 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5557 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5558 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5559 | } |
| 5560 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5561 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5562 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5563 | } |
| 5564 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5565 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5566 | ConnectStatusHelper( |
| 5567 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5568 | } |
| 5569 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5570 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5571 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5572 | } |
| 5573 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5574 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5575 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5576 | } |
| 5577 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5578 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5579 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5580 | } |
| 5581 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5582 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5583 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5584 | } |
| 5585 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5586 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5587 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5588 | } |
| 5589 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5590 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5591 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5592 | } |
| 5593 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5594 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5595 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5596 | } |
| 5597 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5598 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5599 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5600 | } |
| 5601 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5602 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5603 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5604 | } |
| 5605 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5606 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5607 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5608 | } |
| 5609 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5610 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5611 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5612 | } |
| 5613 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5614 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5615 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5616 | } |
| 5617 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5618 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5619 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5620 | } |
| 5621 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5622 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5623 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5624 | } |
| 5625 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5626 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5627 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5628 | } |
| 5629 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5630 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5631 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5632 | } |
| 5633 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5634 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5635 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5636 | } |
| 5637 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5638 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5639 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5640 | } |
| 5641 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5642 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5643 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5644 | } |
| 5645 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5646 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5647 | ConnectStatusHelperWithExpectedStatus( |
| 5648 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5649 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5650 | } |
| 5651 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5652 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5653 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5654 | } |
| 5655 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5656 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5657 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5658 | } |
| 5659 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5660 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5661 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5662 | } |
| 5663 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5664 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5665 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5666 | } |
| 5667 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5668 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5669 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5670 | } |
| 5671 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5672 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5673 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5674 | } |
| 5675 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5676 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5677 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5678 | } |
| 5679 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5680 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5681 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5682 | } |
| 5683 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5684 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5685 | ConnectStatusHelper( |
| 5686 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5687 | } |
| 5688 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5689 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5690 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5691 | } |
| 5692 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5693 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5694 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5695 | } |
| 5696 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5697 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5698 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5699 | } |
| 5700 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5701 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5702 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5703 | } |
| 5704 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5705 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5706 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5707 | } |
| 5708 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5709 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5710 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5711 | } |
| 5712 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5713 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5714 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5715 | } |
| 5716 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5717 | // Test the flow when both the proxy server AND origin server require |
| 5718 | // authentication. Again, this uses basic auth for both since that is |
| 5719 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5720 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5721 | HttpRequestInfo request; |
| 5722 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5723 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5724 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5725 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5726 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5730 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5731 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5732 | MockWrite( |
| 5733 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5734 | "Host: www.example.org\r\n" |
| 5735 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5736 | }; |
| 5737 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5738 | MockRead data_reads1[] = { |
| 5739 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5740 | // Give a couple authenticate options (only the middle one is actually |
| 5741 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5742 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5743 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5744 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5745 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5746 | // Large content-length -- won't matter, as connection will be reset. |
| 5747 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5748 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5749 | }; |
| 5750 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5751 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5752 | // request we should be issuing -- the final header line contains the |
| 5753 | // proxy's credentials. |
| 5754 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5755 | MockWrite( |
| 5756 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5757 | "Host: www.example.org\r\n" |
| 5758 | "Proxy-Connection: keep-alive\r\n" |
| 5759 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5760 | }; |
| 5761 | |
| 5762 | // Now the proxy server lets the request pass through to origin server. |
| 5763 | // The origin server responds with a 401. |
| 5764 | MockRead data_reads2[] = { |
| 5765 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5766 | // Note: We are using the same realm-name as the proxy server. This is |
| 5767 | // completely valid, as realms are unique across hosts. |
| 5768 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5769 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5770 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5771 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5772 | }; |
| 5773 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5774 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5775 | // the credentials for both the proxy and origin server. |
| 5776 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5777 | MockWrite( |
| 5778 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5779 | "Host: www.example.org\r\n" |
| 5780 | "Proxy-Connection: keep-alive\r\n" |
| 5781 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5782 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5783 | }; |
| 5784 | |
| 5785 | // Lastly we get the desired content. |
| 5786 | MockRead data_reads3[] = { |
| 5787 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5788 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5789 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5790 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5791 | }; |
| 5792 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5793 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5794 | data_writes1, arraysize(data_writes1)); |
| 5795 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5796 | data_writes2, arraysize(data_writes2)); |
| 5797 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5798 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5799 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5800 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5801 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5803 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5804 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5805 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5806 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5807 | |
| 5808 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5809 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5810 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5811 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5812 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5813 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5814 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5815 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5816 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5817 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5819 | |
| 5820 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5821 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5823 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5824 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5825 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5827 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5829 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 5830 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5831 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5832 | |
| 5833 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5834 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5835 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5836 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5837 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5838 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5839 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5840 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5841 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5842 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5843 | // authorization headers. |
| 5844 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5845 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5846 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5847 | // bytes in the debugger. |
| 5848 | |
| 5849 | // Enter the correct password and authenticate successfully. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5850 | TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5851 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5852 | request.method = "GET"; |
| 5853 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5854 | |
| 5855 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5856 | // to other auth schemes. |
| 5857 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5858 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5859 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5860 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5862 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5863 | MockWrite data_writes1[] = { |
| 5864 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5865 | "Host: 172.22.68.17\r\n" |
| 5866 | "Connection: keep-alive\r\n\r\n"), |
| 5867 | }; |
| 5868 | |
| 5869 | MockRead data_reads1[] = { |
| 5870 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5871 | // Negotiate and NTLM are often requested together. However, we only want |
| 5872 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5873 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5874 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5875 | MockRead("Connection: close\r\n"), |
| 5876 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5877 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5878 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5879 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5880 | }; |
| 5881 | |
| 5882 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5883 | // After restarting with a null identity, this is the |
| 5884 | // request we should be issuing -- the final header line contains a Type |
| 5885 | // 1 message. |
| 5886 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5887 | "Host: 172.22.68.17\r\n" |
| 5888 | "Connection: keep-alive\r\n" |
| 5889 | "Authorization: NTLM " |
| 5890 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5891 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5892 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5893 | // (the credentials for the origin server). The second request continues |
| 5894 | // on the same connection. |
| 5895 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5896 | "Host: 172.22.68.17\r\n" |
| 5897 | "Connection: keep-alive\r\n" |
| 5898 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5899 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5900 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5901 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5902 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5903 | }; |
| 5904 | |
| 5905 | MockRead data_reads2[] = { |
| 5906 | // The origin server responds with a Type 2 message. |
| 5907 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5908 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5909 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5910 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5911 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5912 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5913 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5914 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5915 | "BtAAAAAAA=\r\n"), |
| 5916 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5917 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5918 | MockRead("You are not authorized to view this page\r\n"), |
| 5919 | |
| 5920 | // Lastly we get the desired content. |
| 5921 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5922 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5923 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5924 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5925 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5926 | }; |
| 5927 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5928 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5929 | data_writes1, arraysize(data_writes1)); |
| 5930 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5931 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5932 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5933 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5935 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5936 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5937 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5938 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5939 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5941 | |
| 5942 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5943 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5945 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5946 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5947 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5948 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5949 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5950 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5951 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5953 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 5954 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5955 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5956 | |
| 5957 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5958 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5959 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5960 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5962 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5963 | ASSERT_TRUE(response); |
| 5964 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5966 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5967 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5968 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5969 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5970 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5971 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5972 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5973 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5974 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5975 | ASSERT_TRUE(response); |
| 5976 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5977 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5978 | } |
| 5979 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5980 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5981 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5982 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5983 | request.method = "GET"; |
| 5984 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5985 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5986 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5987 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5988 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5989 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5990 | MockWrite data_writes1[] = { |
| 5991 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5992 | "Host: 172.22.68.17\r\n" |
| 5993 | "Connection: keep-alive\r\n\r\n"), |
| 5994 | }; |
| 5995 | |
| 5996 | MockRead data_reads1[] = { |
| 5997 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5998 | // Negotiate and NTLM are often requested together. However, we only want |
| 5999 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6000 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6001 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6002 | MockRead("Connection: close\r\n"), |
| 6003 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6004 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6005 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6006 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6007 | }; |
| 6008 | |
| 6009 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6010 | // After restarting with a null identity, this is the |
| 6011 | // request we should be issuing -- the final header line contains a Type |
| 6012 | // 1 message. |
| 6013 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6014 | "Host: 172.22.68.17\r\n" |
| 6015 | "Connection: keep-alive\r\n" |
| 6016 | "Authorization: NTLM " |
| 6017 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6018 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6019 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6020 | // (the credentials for the origin server). The second request continues |
| 6021 | // on the same connection. |
| 6022 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6023 | "Host: 172.22.68.17\r\n" |
| 6024 | "Connection: keep-alive\r\n" |
| 6025 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6026 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6027 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 6028 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 6029 | "4Ww7b7E=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6030 | }; |
| 6031 | |
| 6032 | MockRead data_reads2[] = { |
| 6033 | // The origin server responds with a Type 2 message. |
| 6034 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6035 | MockRead("WWW-Authenticate: NTLM " |
| 6036 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 6037 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6038 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6039 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6040 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6041 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6042 | "BtAAAAAAA=\r\n"), |
| 6043 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6044 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6045 | MockRead("You are not authorized to view this page\r\n"), |
| 6046 | |
| 6047 | // Wrong password. |
| 6048 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6049 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6050 | MockRead("Connection: close\r\n"), |
| 6051 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6052 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6053 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6054 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6055 | }; |
| 6056 | |
| 6057 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6058 | // After restarting with a null identity, this is the |
| 6059 | // request we should be issuing -- the final header line contains a Type |
| 6060 | // 1 message. |
| 6061 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6062 | "Host: 172.22.68.17\r\n" |
| 6063 | "Connection: keep-alive\r\n" |
| 6064 | "Authorization: NTLM " |
| 6065 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6066 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6067 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6068 | // (the credentials for the origin server). The second request continues |
| 6069 | // on the same connection. |
| 6070 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6071 | "Host: 172.22.68.17\r\n" |
| 6072 | "Connection: keep-alive\r\n" |
| 6073 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6074 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6075 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 6076 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 6077 | "+4MUm7c=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6078 | }; |
| 6079 | |
| 6080 | MockRead data_reads3[] = { |
| 6081 | // The origin server responds with a Type 2 message. |
| 6082 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6083 | MockRead("WWW-Authenticate: NTLM " |
| 6084 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 6085 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6086 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6087 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6088 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6089 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6090 | "BtAAAAAAA=\r\n"), |
| 6091 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6092 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6093 | MockRead("You are not authorized to view this page\r\n"), |
| 6094 | |
| 6095 | // Lastly we get the desired content. |
| 6096 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6097 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6098 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6099 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6100 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6101 | }; |
| 6102 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6103 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6104 | data_writes1, arraysize(data_writes1)); |
| 6105 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6106 | data_writes2, arraysize(data_writes2)); |
| 6107 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6108 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6109 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6110 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6111 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6112 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6113 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6114 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6115 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6116 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6117 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6119 | |
| 6120 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6121 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6122 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6123 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6124 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6125 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6126 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6127 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6128 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6129 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6130 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6131 | // Enter the wrong password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6132 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
| 6133 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6134 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6135 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6136 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6137 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6139 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6140 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6141 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6142 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6143 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6144 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6145 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6147 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6148 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6149 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6150 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6151 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6152 | |
| 6153 | // Now enter the right password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6154 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6155 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6156 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6157 | |
| 6158 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6159 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6161 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6163 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6164 | |
| 6165 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6166 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6167 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6168 | |
| 6169 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6170 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6172 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6173 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6174 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6175 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6176 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6177 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6178 | // Test reading a server response which has only headers, and no body. |
| 6179 | // After some maximum number of bytes is consumed, the transaction should |
| 6180 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6181 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6182 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6183 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6184 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6185 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6186 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6187 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6188 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6189 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6190 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6191 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6192 | |
| 6193 | MockRead data_reads[] = { |
| 6194 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6195 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6196 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6197 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6198 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6199 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6200 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6201 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6202 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6203 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6204 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6205 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6206 | |
| 6207 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6208 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6209 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6210 | |
| 6211 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6212 | // establish tunnel. |
| 6213 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6214 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6215 | HttpRequestInfo request; |
| 6216 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6217 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6218 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6219 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6220 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6221 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6223 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6224 | auto trans = |
| 6225 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6226 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6227 | // Since we have proxy, should try to establish tunnel. |
| 6228 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6229 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6230 | "Host: www.example.org:443\r\n" |
| 6231 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6232 | }; |
| 6233 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6234 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6235 | // connection. Usually a proxy would return 501 (not implemented), |
| 6236 | // or 200 (tunnel established). |
| 6237 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6238 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6239 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6240 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6241 | }; |
| 6242 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6243 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6244 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6245 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6247 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6248 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6249 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6250 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6251 | |
| 6252 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6253 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6254 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6255 | // Empty the current queue. This is necessary because idle sockets are |
| 6256 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6257 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6258 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6259 | // We now check to make sure the TCPClientSocket was not added back to |
| 6260 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6261 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6262 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6263 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6264 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6265 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6266 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6267 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6268 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6269 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6270 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6271 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6272 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6273 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6274 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6275 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6276 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6277 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6278 | MockRead data_reads[] = { |
| 6279 | // A part of the response body is received with the response headers. |
| 6280 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6281 | // The rest of the response body is received in two parts. |
| 6282 | MockRead("lo"), |
| 6283 | MockRead(" world"), |
| 6284 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6285 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6286 | }; |
| 6287 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6288 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6289 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6291 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6292 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6293 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6294 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6295 | |
| 6296 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6297 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6298 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6299 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6300 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6301 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6302 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6303 | std::string status_line = response->headers->GetStatusLine(); |
| 6304 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6305 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6306 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6307 | |
| 6308 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6309 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6310 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6311 | EXPECT_EQ("hello world", response_data); |
| 6312 | |
| 6313 | // Empty the current queue. This is necessary because idle sockets are |
| 6314 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6315 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6316 | |
| 6317 | // 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] | 6318 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6319 | } |
| 6320 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6321 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6322 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6323 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6324 | HttpRequestInfo request; |
| 6325 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6326 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6327 | |
| 6328 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6329 | MockWrite( |
| 6330 | "GET / HTTP/1.1\r\n" |
| 6331 | "Host: www.example.org\r\n" |
| 6332 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6333 | }; |
| 6334 | |
| 6335 | MockRead data_reads[] = { |
| 6336 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6337 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6338 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6339 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6340 | }; |
| 6341 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6342 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6343 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6344 | |
| 6345 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6346 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6347 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6349 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6350 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6351 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6352 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6354 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6355 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6356 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6357 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6358 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6359 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6360 | ASSERT_TRUE(response); |
| 6361 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6362 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6363 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6364 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6365 | |
| 6366 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6367 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6368 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6369 | EXPECT_EQ("hello world", response_data); |
| 6370 | |
| 6371 | // Empty the current queue. This is necessary because idle sockets are |
| 6372 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6373 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6374 | |
| 6375 | // 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] | 6376 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6377 | } |
| 6378 | |
| 6379 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6380 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6381 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6382 | HttpRequestInfo request; |
| 6383 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6384 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6385 | |
| 6386 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6387 | MockWrite( |
| 6388 | "GET / HTTP/1.1\r\n" |
| 6389 | "Host: www.example.org\r\n" |
| 6390 | "Connection: keep-alive\r\n\r\n"), |
| 6391 | MockWrite( |
| 6392 | "GET / HTTP/1.1\r\n" |
| 6393 | "Host: www.example.org\r\n" |
| 6394 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6395 | }; |
| 6396 | |
| 6397 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6398 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6399 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6400 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6401 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6402 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6403 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6404 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6405 | |
| 6406 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6407 | data_writes, arraysize(data_writes)); |
| 6408 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6409 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6410 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6411 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6412 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6413 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6414 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6416 | auto trans = |
| 6417 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6418 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6419 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6420 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6421 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6422 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6423 | |
| 6424 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6425 | ASSERT_TRUE(response); |
| 6426 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6427 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6428 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6429 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6430 | |
| 6431 | std::string response_data; |
| 6432 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6433 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6434 | EXPECT_EQ("hello world", response_data); |
| 6435 | |
| 6436 | // Empty the current queue. This is necessary because idle sockets are |
| 6437 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6438 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6439 | |
| 6440 | // 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] | 6441 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6442 | |
| 6443 | // Now start the second transaction, which should reuse the previous socket. |
| 6444 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6445 | trans = |
| 6446 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6447 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6448 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6449 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6450 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6451 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6452 | |
| 6453 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6454 | ASSERT_TRUE(response); |
| 6455 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6456 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6457 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6458 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6459 | |
| 6460 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6461 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6462 | EXPECT_EQ("hello world", response_data); |
| 6463 | |
| 6464 | // Empty the current queue. This is necessary because idle sockets are |
| 6465 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6466 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6467 | |
| 6468 | // 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] | 6469 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6470 | } |
| 6471 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6472 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6473 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6474 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6475 | HttpRequestInfo request; |
| 6476 | request.method = "GET"; |
| 6477 | request.url = GURL("http://www.example.org/"); |
| 6478 | request.load_flags = 0; |
| 6479 | |
| 6480 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6482 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6483 | |
| 6484 | MockRead data_reads[] = { |
| 6485 | // A part of the response body is received with the response headers. |
| 6486 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6487 | // The rest of the response body is received in two parts. |
| 6488 | MockRead("lo"), MockRead(" world"), |
| 6489 | MockRead("junk"), // Should not be read!! |
| 6490 | MockRead(SYNCHRONOUS, OK), |
| 6491 | }; |
| 6492 | |
| 6493 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6494 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6495 | |
| 6496 | TestCompletionCallback callback; |
| 6497 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6498 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6499 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6500 | |
| 6501 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6502 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6503 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6504 | ASSERT_TRUE(response); |
| 6505 | EXPECT_TRUE(response->headers); |
| 6506 | std::string status_line = response->headers->GetStatusLine(); |
| 6507 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6508 | |
| 6509 | // Make memory critical notification and ensure the transaction still has been |
| 6510 | // operating right. |
| 6511 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6512 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6513 | base::RunLoop().RunUntilIdle(); |
| 6514 | |
| 6515 | // Socket should not be flushed as long as it is not idle. |
| 6516 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6517 | |
| 6518 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6519 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6520 | EXPECT_THAT(rv, IsOk()); |
| 6521 | EXPECT_EQ("hello world", response_data); |
| 6522 | |
| 6523 | // Empty the current queue. This is necessary because idle sockets are |
| 6524 | // added to the connection pool asynchronously with a PostTask. |
| 6525 | base::RunLoop().RunUntilIdle(); |
| 6526 | |
| 6527 | // We now check to make sure the socket was added back to the pool. |
| 6528 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6529 | |
| 6530 | // Idle sockets should be flushed now. |
| 6531 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6532 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6533 | base::RunLoop().RunUntilIdle(); |
| 6534 | |
| 6535 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6536 | } |
| 6537 | |
| 6538 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6539 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6540 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6541 | HttpRequestInfo request; |
| 6542 | request.method = "GET"; |
| 6543 | request.url = GURL("https://www.example.org/"); |
| 6544 | request.load_flags = 0; |
| 6545 | |
| 6546 | MockWrite data_writes[] = { |
| 6547 | MockWrite("GET / HTTP/1.1\r\n" |
| 6548 | "Host: www.example.org\r\n" |
| 6549 | "Connection: keep-alive\r\n\r\n"), |
| 6550 | }; |
| 6551 | |
| 6552 | MockRead data_reads[] = { |
| 6553 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6554 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6555 | |
| 6556 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6557 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6558 | |
| 6559 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6560 | arraysize(data_writes)); |
| 6561 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6562 | |
| 6563 | TestCompletionCallback callback; |
| 6564 | |
| 6565 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6566 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6567 | |
| 6568 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6569 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6570 | |
| 6571 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6572 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6573 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6574 | ASSERT_TRUE(response); |
| 6575 | ASSERT_TRUE(response->headers); |
| 6576 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6577 | |
| 6578 | // Make memory critical notification and ensure the transaction still has been |
| 6579 | // operating right. |
| 6580 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6581 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6582 | base::RunLoop().RunUntilIdle(); |
| 6583 | |
| 6584 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6585 | |
| 6586 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6587 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6588 | EXPECT_THAT(rv, IsOk()); |
| 6589 | EXPECT_EQ("hello world", response_data); |
| 6590 | |
| 6591 | // Empty the current queue. This is necessary because idle sockets are |
| 6592 | // added to the connection pool asynchronously with a PostTask. |
| 6593 | base::RunLoop().RunUntilIdle(); |
| 6594 | |
| 6595 | // We now check to make sure the socket was added back to the pool. |
| 6596 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6597 | |
| 6598 | // Make memory notification once again and ensure idle socket is closed. |
| 6599 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6600 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6601 | base::RunLoop().RunUntilIdle(); |
| 6602 | |
| 6603 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6604 | } |
| 6605 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6606 | // Make sure that we recycle a socket after a zero-length response. |
| 6607 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6608 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6609 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6610 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6611 | request.url = GURL( |
| 6612 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6613 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6614 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6615 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6616 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6617 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6618 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6619 | MockRead data_reads[] = { |
| 6620 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6621 | "Content-Length: 0\r\n" |
| 6622 | "Content-Type: text/html\r\n\r\n"), |
| 6623 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6624 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6625 | }; |
| 6626 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6627 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6628 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6629 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6630 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6631 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6632 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6633 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6634 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6635 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6636 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6638 | |
| 6639 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6640 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6641 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6642 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6643 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6644 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6645 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6646 | std::string status_line = response->headers->GetStatusLine(); |
| 6647 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6648 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6649 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6650 | |
| 6651 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6652 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6653 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6654 | EXPECT_EQ("", response_data); |
| 6655 | |
| 6656 | // Empty the current queue. This is necessary because idle sockets are |
| 6657 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6658 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6659 | |
| 6660 | // 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] | 6661 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6662 | } |
| 6663 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6664 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6665 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6666 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 6667 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6668 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6669 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6670 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6671 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6672 | // after use. |
| 6673 | request[0].method = "GET"; |
| 6674 | request[0].url = GURL("http://www.google.com/"); |
| 6675 | request[0].load_flags = 0; |
| 6676 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6677 | // transaction 1. The first attempts fails when writing the POST data. |
| 6678 | // This causes the transaction to retry with a new socket. The second |
| 6679 | // attempt succeeds. |
| 6680 | request[1].method = "POST"; |
| 6681 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6682 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6683 | request[1].load_flags = 0; |
| 6684 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6685 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6686 | |
| 6687 | // The first socket is used for transaction 1 and the first attempt of |
| 6688 | // transaction 2. |
| 6689 | |
| 6690 | // The response of transaction 1. |
| 6691 | MockRead data_reads1[] = { |
| 6692 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6693 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6694 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6695 | }; |
| 6696 | // The mock write results of transaction 1 and the first attempt of |
| 6697 | // transaction 2. |
| 6698 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6699 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6700 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6701 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6702 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6703 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6704 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6705 | |
| 6706 | // The second socket is used for the second attempt of transaction 2. |
| 6707 | |
| 6708 | // The response of transaction 2. |
| 6709 | MockRead data_reads2[] = { |
| 6710 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6711 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6712 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6713 | }; |
| 6714 | // The mock write results of the second attempt of transaction 2. |
| 6715 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6716 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6717 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6718 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6719 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6720 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6721 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6722 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6723 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6724 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6725 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6726 | "hello world", "welcome" |
| 6727 | }; |
| 6728 | |
| 6729 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6730 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6731 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6732 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6733 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6734 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6735 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6736 | |
| 6737 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6738 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6739 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6740 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6741 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6742 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6743 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6744 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6745 | |
| 6746 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6747 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6748 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6749 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6750 | } |
| 6751 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6752 | |
| 6753 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6754 | // 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] | 6755 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6756 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6757 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6759 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6760 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6761 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6763 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6764 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6765 | // The password contains an escaped character -- for this test to pass it |
| 6766 | // will need to be unescaped by HttpNetworkTransaction. |
| 6767 | EXPECT_EQ("b%40r", request.url.password()); |
| 6768 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6769 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6770 | MockWrite( |
| 6771 | "GET / HTTP/1.1\r\n" |
| 6772 | "Host: www.example.org\r\n" |
| 6773 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6774 | }; |
| 6775 | |
| 6776 | MockRead data_reads1[] = { |
| 6777 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6778 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6779 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6780 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6781 | }; |
| 6782 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6783 | // After the challenge above, the transaction will be restarted using the |
| 6784 | // identity from the url (foo, b@r) to answer the challenge. |
| 6785 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6786 | MockWrite( |
| 6787 | "GET / HTTP/1.1\r\n" |
| 6788 | "Host: www.example.org\r\n" |
| 6789 | "Connection: keep-alive\r\n" |
| 6790 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6791 | }; |
| 6792 | |
| 6793 | MockRead data_reads2[] = { |
| 6794 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6795 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6796 | MockRead(SYNCHRONOUS, OK), |
| 6797 | }; |
| 6798 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6799 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6800 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6801 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6802 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6803 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6804 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6806 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6807 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6808 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6809 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6810 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6811 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6812 | |
| 6813 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6814 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6816 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6817 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6818 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6819 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6820 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6821 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6822 | |
| 6823 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6824 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6825 | |
| 6826 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6827 | |
| 6828 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6829 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6830 | } |
| 6831 | |
| 6832 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6833 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6834 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6835 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6836 | HttpRequestInfo request; |
| 6837 | request.method = "GET"; |
| 6838 | // Note: the URL has a username:password in it. The password "baz" is |
| 6839 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6840 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6841 | |
| 6842 | request.load_flags = LOAD_NORMAL; |
| 6843 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6844 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6845 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6846 | |
| 6847 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6848 | MockWrite( |
| 6849 | "GET / HTTP/1.1\r\n" |
| 6850 | "Host: www.example.org\r\n" |
| 6851 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6852 | }; |
| 6853 | |
| 6854 | MockRead data_reads1[] = { |
| 6855 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6856 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6857 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6858 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6859 | }; |
| 6860 | |
| 6861 | // After the challenge above, the transaction will be restarted using the |
| 6862 | // identity from the url (foo, baz) to answer the challenge. |
| 6863 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6864 | MockWrite( |
| 6865 | "GET / HTTP/1.1\r\n" |
| 6866 | "Host: www.example.org\r\n" |
| 6867 | "Connection: keep-alive\r\n" |
| 6868 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6869 | }; |
| 6870 | |
| 6871 | MockRead data_reads2[] = { |
| 6872 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6873 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6874 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6875 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6876 | }; |
| 6877 | |
| 6878 | // After the challenge above, the transaction will be restarted using the |
| 6879 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6880 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6881 | MockWrite( |
| 6882 | "GET / HTTP/1.1\r\n" |
| 6883 | "Host: www.example.org\r\n" |
| 6884 | "Connection: keep-alive\r\n" |
| 6885 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6886 | }; |
| 6887 | |
| 6888 | MockRead data_reads3[] = { |
| 6889 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6890 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6891 | MockRead(SYNCHRONOUS, OK), |
| 6892 | }; |
| 6893 | |
| 6894 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6895 | data_writes1, arraysize(data_writes1)); |
| 6896 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6897 | data_writes2, arraysize(data_writes2)); |
| 6898 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6899 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6900 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6901 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6902 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6903 | |
| 6904 | TestCompletionCallback callback1; |
| 6905 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6906 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6907 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6908 | |
| 6909 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6910 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6911 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6912 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6913 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6914 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6915 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6916 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6917 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6918 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6919 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6920 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6921 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6922 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6923 | |
| 6924 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6925 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6926 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6927 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6928 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6929 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6930 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6931 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6932 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6933 | |
| 6934 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6935 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6936 | |
| 6937 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6938 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6939 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6940 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6941 | } |
| 6942 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6943 | |
| 6944 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6945 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6946 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6947 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6948 | HttpRequestInfo request; |
| 6949 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6950 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6951 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6952 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6953 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6954 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6955 | |
| 6956 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6957 | MockWrite( |
| 6958 | "GET / HTTP/1.1\r\n" |
| 6959 | "Host: www.example.org\r\n" |
| 6960 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6961 | }; |
| 6962 | |
| 6963 | MockRead data_reads1[] = { |
| 6964 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6965 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6966 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6967 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6968 | }; |
| 6969 | |
| 6970 | // After the challenge above, the transaction will be restarted using the |
| 6971 | // identity supplied by the user, not the one in the URL, to answer the |
| 6972 | // challenge. |
| 6973 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6974 | MockWrite( |
| 6975 | "GET / HTTP/1.1\r\n" |
| 6976 | "Host: www.example.org\r\n" |
| 6977 | "Connection: keep-alive\r\n" |
| 6978 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6979 | }; |
| 6980 | |
| 6981 | MockRead data_reads3[] = { |
| 6982 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6983 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6984 | MockRead(SYNCHRONOUS, OK), |
| 6985 | }; |
| 6986 | |
| 6987 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6988 | data_writes1, arraysize(data_writes1)); |
| 6989 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6990 | data_writes3, arraysize(data_writes3)); |
| 6991 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6992 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6993 | |
| 6994 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6995 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6996 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6997 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6998 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6999 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7000 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7001 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7002 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7003 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7004 | |
| 7005 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7006 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7007 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7008 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7009 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7010 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7012 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7013 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7014 | |
| 7015 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7016 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7017 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7018 | |
| 7019 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7020 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7021 | } |
| 7022 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7023 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7024 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7025 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7026 | |
| 7027 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7028 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7029 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7030 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7031 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7033 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7034 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7035 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7036 | MockWrite( |
| 7037 | "GET /x/y/z HTTP/1.1\r\n" |
| 7038 | "Host: www.example.org\r\n" |
| 7039 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7040 | }; |
| 7041 | |
| 7042 | MockRead data_reads1[] = { |
| 7043 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7044 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7045 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7046 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7047 | }; |
| 7048 | |
| 7049 | // Resend with authorization (username=foo, password=bar) |
| 7050 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7051 | MockWrite( |
| 7052 | "GET /x/y/z HTTP/1.1\r\n" |
| 7053 | "Host: www.example.org\r\n" |
| 7054 | "Connection: keep-alive\r\n" |
| 7055 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7056 | }; |
| 7057 | |
| 7058 | // Sever accepts the authorization. |
| 7059 | MockRead data_reads2[] = { |
| 7060 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7061 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7062 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7063 | }; |
| 7064 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7065 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7066 | data_writes1, arraysize(data_writes1)); |
| 7067 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7068 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7069 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7070 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7071 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7072 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7073 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7074 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7075 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7076 | |
| 7077 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7078 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7079 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7080 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7081 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7082 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7083 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7084 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7085 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7086 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7087 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7088 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7089 | |
| 7090 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7091 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7092 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7093 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7094 | ASSERT_TRUE(response); |
| 7095 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7096 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7097 | } |
| 7098 | |
| 7099 | // ------------------------------------------------------------------------ |
| 7100 | |
| 7101 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7102 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7103 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7104 | request.method = "GET"; |
| 7105 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7106 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7107 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7108 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7109 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7110 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7111 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7112 | MockWrite( |
| 7113 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7114 | "Host: www.example.org\r\n" |
| 7115 | "Connection: keep-alive\r\n" |
| 7116 | // Send preemptive authorization for MyRealm1 |
| 7117 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7118 | }; |
| 7119 | |
| 7120 | // The server didn't like the preemptive authorization, and |
| 7121 | // challenges us for a different realm (MyRealm2). |
| 7122 | MockRead data_reads1[] = { |
| 7123 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7124 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7125 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7126 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7127 | }; |
| 7128 | |
| 7129 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7130 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7131 | MockWrite( |
| 7132 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7133 | "Host: www.example.org\r\n" |
| 7134 | "Connection: keep-alive\r\n" |
| 7135 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7136 | }; |
| 7137 | |
| 7138 | // Sever accepts the authorization. |
| 7139 | MockRead data_reads2[] = { |
| 7140 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7141 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7142 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7143 | }; |
| 7144 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7145 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7146 | data_writes1, arraysize(data_writes1)); |
| 7147 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7148 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7149 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7150 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7151 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7152 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7153 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7154 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7155 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7156 | |
| 7157 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7158 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7159 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7160 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7161 | ASSERT_TRUE(response); |
| 7162 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7163 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7164 | EXPECT_EQ("http://www.example.org", |
| 7165 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7166 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7167 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7168 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7169 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7170 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7171 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7172 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7173 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7174 | |
| 7175 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7176 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7177 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7178 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7179 | ASSERT_TRUE(response); |
| 7180 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7181 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7182 | } |
| 7183 | |
| 7184 | // ------------------------------------------------------------------------ |
| 7185 | |
| 7186 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7187 | // succeed with preemptive authorization. |
| 7188 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7189 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7190 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7191 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7192 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7193 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7194 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7195 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7196 | MockWrite( |
| 7197 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7198 | "Host: www.example.org\r\n" |
| 7199 | "Connection: keep-alive\r\n" |
| 7200 | // The authorization for MyRealm1 gets sent preemptively |
| 7201 | // (since the url is in the same protection space) |
| 7202 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7203 | }; |
| 7204 | |
| 7205 | // Sever accepts the preemptive authorization |
| 7206 | MockRead data_reads1[] = { |
| 7207 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7208 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7209 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7210 | }; |
| 7211 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7212 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7213 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7214 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7215 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7216 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7217 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7218 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7219 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7220 | |
| 7221 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7222 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7223 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7224 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7225 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7226 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7227 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7228 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7229 | } |
| 7230 | |
| 7231 | // ------------------------------------------------------------------------ |
| 7232 | |
| 7233 | // Transaction 4: request another URL in MyRealm (however the |
| 7234 | // url is not known to belong to the protection space, so no pre-auth). |
| 7235 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7236 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7237 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7238 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7240 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7241 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7242 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7243 | MockWrite( |
| 7244 | "GET /x/1 HTTP/1.1\r\n" |
| 7245 | "Host: www.example.org\r\n" |
| 7246 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7247 | }; |
| 7248 | |
| 7249 | MockRead data_reads1[] = { |
| 7250 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7251 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7252 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7253 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7254 | }; |
| 7255 | |
| 7256 | // Resend with authorization from MyRealm's cache. |
| 7257 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7258 | MockWrite( |
| 7259 | "GET /x/1 HTTP/1.1\r\n" |
| 7260 | "Host: www.example.org\r\n" |
| 7261 | "Connection: keep-alive\r\n" |
| 7262 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7263 | }; |
| 7264 | |
| 7265 | // Sever accepts the authorization. |
| 7266 | MockRead data_reads2[] = { |
| 7267 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7268 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7269 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7270 | }; |
| 7271 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7272 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7273 | data_writes1, arraysize(data_writes1)); |
| 7274 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7275 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7276 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7277 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7278 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7279 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7280 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7281 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7283 | |
| 7284 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7285 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7286 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7287 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7288 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7289 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7290 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7291 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7292 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7293 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7294 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7295 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7296 | ASSERT_TRUE(response); |
| 7297 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7298 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7299 | } |
| 7300 | |
| 7301 | // ------------------------------------------------------------------------ |
| 7302 | |
| 7303 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7304 | // cached identity. Should invalidate and re-prompt. |
| 7305 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7306 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7307 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7308 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7309 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7310 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7311 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7312 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7313 | MockWrite( |
| 7314 | "GET /p/q/t HTTP/1.1\r\n" |
| 7315 | "Host: www.example.org\r\n" |
| 7316 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7317 | }; |
| 7318 | |
| 7319 | MockRead data_reads1[] = { |
| 7320 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7321 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7322 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7323 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7324 | }; |
| 7325 | |
| 7326 | // Resend with authorization from cache for MyRealm. |
| 7327 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7328 | MockWrite( |
| 7329 | "GET /p/q/t HTTP/1.1\r\n" |
| 7330 | "Host: www.example.org\r\n" |
| 7331 | "Connection: keep-alive\r\n" |
| 7332 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7333 | }; |
| 7334 | |
| 7335 | // Sever rejects the authorization. |
| 7336 | MockRead data_reads2[] = { |
| 7337 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7338 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7339 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7340 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7341 | }; |
| 7342 | |
| 7343 | // At this point we should prompt for new credentials for MyRealm. |
| 7344 | // Restart with username=foo3, password=foo4. |
| 7345 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7346 | MockWrite( |
| 7347 | "GET /p/q/t HTTP/1.1\r\n" |
| 7348 | "Host: www.example.org\r\n" |
| 7349 | "Connection: keep-alive\r\n" |
| 7350 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7351 | }; |
| 7352 | |
| 7353 | // Sever accepts the authorization. |
| 7354 | MockRead data_reads3[] = { |
| 7355 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7356 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7357 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7358 | }; |
| 7359 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7360 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7361 | data_writes1, arraysize(data_writes1)); |
| 7362 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7363 | data_writes2, arraysize(data_writes2)); |
| 7364 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7365 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7366 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7367 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7368 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7370 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7371 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7372 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7373 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7374 | |
| 7375 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7376 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7377 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7378 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7379 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7380 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7381 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7382 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7383 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7384 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7385 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7386 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7387 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7388 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7389 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7390 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7391 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7392 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7393 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7394 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7395 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7396 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7397 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7398 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7399 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7400 | ASSERT_TRUE(response); |
| 7401 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7402 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7403 | } |
| 7404 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7405 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7406 | // Tests that nonce count increments when multiple auth attempts |
| 7407 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7408 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7409 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7410 | new HttpAuthHandlerDigest::Factory(); |
| 7411 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7412 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7413 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7414 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7416 | |
| 7417 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7418 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7419 | HttpRequestInfo request; |
| 7420 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7421 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7422 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7423 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7424 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7425 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7426 | MockWrite( |
| 7427 | "GET /x/y/z HTTP/1.1\r\n" |
| 7428 | "Host: www.example.org\r\n" |
| 7429 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7430 | }; |
| 7431 | |
| 7432 | MockRead data_reads1[] = { |
| 7433 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7434 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7435 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7436 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7437 | }; |
| 7438 | |
| 7439 | // Resend with authorization (username=foo, password=bar) |
| 7440 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7441 | MockWrite( |
| 7442 | "GET /x/y/z HTTP/1.1\r\n" |
| 7443 | "Host: www.example.org\r\n" |
| 7444 | "Connection: keep-alive\r\n" |
| 7445 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7446 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7447 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7448 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7449 | }; |
| 7450 | |
| 7451 | // Sever accepts the authorization. |
| 7452 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7453 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7454 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7455 | }; |
| 7456 | |
| 7457 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7458 | data_writes1, arraysize(data_writes1)); |
| 7459 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7460 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7461 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7462 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7464 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7465 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7466 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7468 | |
| 7469 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7470 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7471 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7472 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7473 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7474 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7476 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7478 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7479 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7481 | |
| 7482 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7483 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7485 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7486 | ASSERT_TRUE(response); |
| 7487 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7488 | } |
| 7489 | |
| 7490 | // ------------------------------------------------------------------------ |
| 7491 | |
| 7492 | // Transaction 2: Request another resource in digestive's protection space. |
| 7493 | // This will preemptively add an Authorization header which should have an |
| 7494 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7495 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7496 | HttpRequestInfo request; |
| 7497 | request.method = "GET"; |
| 7498 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7499 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7500 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7501 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7502 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7503 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7504 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7505 | MockWrite( |
| 7506 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7507 | "Host: www.example.org\r\n" |
| 7508 | "Connection: keep-alive\r\n" |
| 7509 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7510 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7511 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7512 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7513 | }; |
| 7514 | |
| 7515 | // Sever accepts the authorization. |
| 7516 | MockRead data_reads1[] = { |
| 7517 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7518 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7519 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7520 | }; |
| 7521 | |
| 7522 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7523 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7524 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7525 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7526 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7527 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7528 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7529 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7530 | |
| 7531 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7532 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7534 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7535 | ASSERT_TRUE(response); |
| 7536 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7537 | } |
| 7538 | } |
| 7539 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7540 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7541 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7542 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7543 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7544 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7545 | |
| 7546 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7547 | trans.read_buf_ = new IOBuffer(15); |
| 7548 | trans.read_buf_len_ = 15; |
| 7549 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7550 | |
| 7551 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7552 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7553 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7554 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7555 | response->response_time = base::Time::Now(); |
| 7556 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7557 | |
| 7558 | { // Setup state for response_.vary_data |
| 7559 | HttpRequestInfo request; |
| 7560 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7561 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7562 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7563 | request.extra_headers.SetHeader("Foo", "1"); |
| 7564 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7565 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7566 | } |
| 7567 | |
| 7568 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7569 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7570 | |
| 7571 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7572 | EXPECT_FALSE(trans.read_buf_); |
| 7573 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7574 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7575 | EXPECT_FALSE(response->auth_challenge); |
| 7576 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7577 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7578 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7579 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7580 | } |
| 7581 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7582 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7583 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7584 | HttpRequestInfo request; |
| 7585 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7586 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7587 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7588 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7589 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7590 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7591 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7592 | MockWrite( |
| 7593 | "GET / HTTP/1.1\r\n" |
| 7594 | "Host: www.example.org\r\n" |
| 7595 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7596 | }; |
| 7597 | |
| 7598 | MockRead data_reads[] = { |
| 7599 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7600 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7601 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7602 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7603 | }; |
| 7604 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7605 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7606 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7607 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7608 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7609 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7610 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7611 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7612 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7613 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7614 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7615 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7616 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7617 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7618 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7619 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7620 | |
| 7621 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7622 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7623 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7624 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7625 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7626 | |
| 7627 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7628 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7629 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7630 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7631 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7632 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7633 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7634 | } |
| 7635 | |
| 7636 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7637 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7638 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7639 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7640 | |
| 7641 | HttpRequestInfo request; |
| 7642 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7643 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7644 | |
| 7645 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7646 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7647 | "Host: www.example.org:443\r\n" |
| 7648 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7649 | }; |
| 7650 | |
| 7651 | MockRead proxy_reads[] = { |
| 7652 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7653 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7654 | }; |
| 7655 | |
| 7656 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7657 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7658 | "Host: www.example.org:443\r\n" |
| 7659 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7660 | MockWrite("GET / HTTP/1.1\r\n" |
| 7661 | "Host: www.example.org\r\n" |
| 7662 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7663 | }; |
| 7664 | |
| 7665 | MockRead data_reads[] = { |
| 7666 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7667 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7668 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7669 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7670 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7671 | }; |
| 7672 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7673 | StaticSocketDataProvider ssl_bad_certificate( |
| 7674 | proxy_reads, arraysize(proxy_reads), |
| 7675 | proxy_writes, arraysize(proxy_writes)); |
| 7676 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7677 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7678 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7679 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7680 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7681 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7682 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7683 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7684 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7685 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7686 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7687 | |
| 7688 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7689 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7690 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7691 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7692 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7693 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7694 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7695 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7696 | |
| 7697 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7698 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7700 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7701 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7702 | |
| 7703 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7704 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7705 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7706 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7707 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7708 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7709 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7710 | } |
| 7711 | } |
| 7712 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7713 | |
| 7714 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7715 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7716 | session_deps_.proxy_service = |
| 7717 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7718 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7719 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7720 | |
| 7721 | HttpRequestInfo request; |
| 7722 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7723 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7724 | |
| 7725 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7726 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7727 | "Host: www.example.org:443\r\n" |
| 7728 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7729 | MockWrite("GET / HTTP/1.1\r\n" |
| 7730 | "Host: www.example.org\r\n" |
| 7731 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7732 | }; |
| 7733 | |
| 7734 | MockRead data_reads[] = { |
| 7735 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7736 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7737 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7738 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7739 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7740 | }; |
| 7741 | |
| 7742 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7743 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7744 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7745 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7746 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7747 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7748 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7749 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7750 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7751 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7752 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7753 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7754 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7755 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7756 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7757 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7758 | |
| 7759 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7760 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7761 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7762 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7763 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7764 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 7765 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7766 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7767 | EXPECT_EQ(200, response->headers->response_code()); |
| 7768 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7769 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7770 | |
| 7771 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7772 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7773 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7774 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7775 | } |
| 7776 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7777 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7778 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7779 | session_deps_.proxy_service = |
| 7780 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7781 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7782 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7783 | |
| 7784 | HttpRequestInfo request; |
| 7785 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7786 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7787 | |
| 7788 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7789 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7790 | "Host: www.example.org:443\r\n" |
| 7791 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7792 | }; |
| 7793 | |
| 7794 | MockRead data_reads[] = { |
| 7795 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7796 | MockRead("Location: http://login.example.com/\r\n"), |
| 7797 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7798 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7799 | }; |
| 7800 | |
| 7801 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7802 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7803 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7804 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7805 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7806 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7808 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7809 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7810 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7811 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7812 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7813 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7815 | |
| 7816 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7817 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7818 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7819 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7820 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7821 | |
| 7822 | EXPECT_EQ(302, response->headers->response_code()); |
| 7823 | std::string url; |
| 7824 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7825 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7826 | |
| 7827 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7828 | // timing for the proxy connection instead of the connection to the host, |
| 7829 | // and no send / receive times. |
| 7830 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7831 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7832 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7833 | |
| 7834 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 7835 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7836 | |
| 7837 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7838 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7839 | load_timing_info.proxy_resolve_end); |
| 7840 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7841 | load_timing_info.connect_timing.connect_start); |
| 7842 | ExpectConnectTimingHasTimes( |
| 7843 | load_timing_info.connect_timing, |
| 7844 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7845 | |
| 7846 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7847 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7848 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7849 | } |
| 7850 | |
| 7851 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7852 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7853 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7854 | |
| 7855 | HttpRequestInfo request; |
| 7856 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7857 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7858 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7859 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7860 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7861 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 7862 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7863 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7864 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 7865 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7866 | }; |
| 7867 | |
| 7868 | static const char* const kExtraHeaders[] = { |
| 7869 | "location", |
| 7870 | "http://login.example.com/", |
| 7871 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7872 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7873 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7874 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7875 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7876 | }; |
| 7877 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7878 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7879 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7880 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7881 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7882 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7883 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7884 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7885 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7886 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7887 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7889 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7890 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7891 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7892 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7893 | |
| 7894 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7895 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7896 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7897 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7898 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7899 | |
| 7900 | EXPECT_EQ(302, response->headers->response_code()); |
| 7901 | std::string url; |
| 7902 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7903 | EXPECT_EQ("http://login.example.com/", url); |
| 7904 | } |
| 7905 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7906 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7907 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7908 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7909 | |
| 7910 | HttpRequestInfo request; |
| 7911 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7912 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7913 | |
| 7914 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7915 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7916 | "Host: www.example.org:443\r\n" |
| 7917 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7918 | }; |
| 7919 | |
| 7920 | MockRead data_reads[] = { |
| 7921 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7922 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7923 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7924 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7925 | }; |
| 7926 | |
| 7927 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7928 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7929 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7930 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7931 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7932 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7933 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7934 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7935 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7936 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7937 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7938 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7939 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7941 | |
| 7942 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7943 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7944 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7945 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7946 | } |
| 7947 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7948 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7949 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7950 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7951 | |
| 7952 | HttpRequestInfo request; |
| 7953 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7954 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7955 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7956 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7957 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7958 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 7959 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7960 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7961 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7962 | }; |
| 7963 | |
| 7964 | static const char* const kExtraHeaders[] = { |
| 7965 | "location", |
| 7966 | "http://login.example.com/", |
| 7967 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7968 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7969 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7970 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7971 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7972 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7973 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7974 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7975 | }; |
| 7976 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7977 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7978 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7979 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7980 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7981 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7982 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7983 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7984 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7985 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7986 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7987 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7988 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7989 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7990 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7991 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7992 | |
| 7993 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7994 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7995 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7996 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7997 | } |
| 7998 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7999 | // Test the request-challenge-retry sequence for basic auth, through |
| 8000 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8001 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8002 | HttpRequestInfo request; |
| 8003 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8004 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8005 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8006 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8007 | |
| 8008 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8009 | session_deps_.proxy_service = |
| 8010 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8011 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8012 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8013 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8014 | |
| 8015 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8016 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8017 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8018 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8019 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8020 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8021 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8022 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8023 | // be issuing -- the final header line contains the credentials. |
| 8024 | const char* const kAuthCredentials[] = { |
| 8025 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8026 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8027 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8028 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8029 | HostPortPair("www.example.org", 443))); |
| 8030 | // fetch https://www.example.org/ via HTTP |
| 8031 | const char get[] = |
| 8032 | "GET / HTTP/1.1\r\n" |
| 8033 | "Host: www.example.org\r\n" |
| 8034 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8035 | SpdySerializedFrame wrapped_get( |
| 8036 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8037 | |
| 8038 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8039 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8040 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8041 | }; |
| 8042 | |
| 8043 | // The proxy responds to the connect with a 407, using a persistent |
| 8044 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8045 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8046 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8047 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8048 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8049 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8050 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8051 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8052 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8053 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8054 | "Content-Length: 5\r\n\r\n"; |
| 8055 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8056 | SpdySerializedFrame wrapped_get_resp( |
| 8057 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8058 | SpdySerializedFrame wrapped_body( |
| 8059 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8060 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8061 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8062 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8063 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8064 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8065 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8066 | }; |
| 8067 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8068 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8069 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8070 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8071 | // Negotiate SPDY to the proxy |
| 8072 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8073 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8074 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8075 | // Vanilla SSL to the server |
| 8076 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8077 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8078 | |
| 8079 | TestCompletionCallback callback1; |
| 8080 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8081 | auto trans = |
| 8082 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8083 | |
| 8084 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8085 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8086 | |
| 8087 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8088 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8089 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8090 | log.GetEntries(&entries); |
| 8091 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8092 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8093 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8094 | ExpectLogContainsSomewhere( |
| 8095 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8096 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8097 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8098 | |
| 8099 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8100 | ASSERT_TRUE(response); |
| 8101 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8102 | EXPECT_EQ(407, response->headers->response_code()); |
| 8103 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8104 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8105 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8106 | |
| 8107 | TestCompletionCallback callback2; |
| 8108 | |
| 8109 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8110 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8111 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8112 | |
| 8113 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8114 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8115 | |
| 8116 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8117 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8118 | |
| 8119 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8120 | EXPECT_EQ(200, response->headers->response_code()); |
| 8121 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8122 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8123 | |
| 8124 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8125 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8126 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8127 | LoadTimingInfo load_timing_info; |
| 8128 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8129 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8130 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8131 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8132 | trans.reset(); |
| 8133 | session->CloseAllConnections(); |
| 8134 | } |
| 8135 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8136 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8137 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8138 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8139 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8140 | auto proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8141 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8142 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8143 | HttpRequestInfo request; |
| 8144 | HttpRequestInfo push_request; |
| 8145 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8146 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8147 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8148 | push_request.method = "GET"; |
| 8149 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8150 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8151 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8152 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8153 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8154 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8155 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8156 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8157 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8158 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8159 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8160 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8161 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8162 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8163 | SpdySerializedFrame stream2_priority( |
| 8164 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8165 | |
| 8166 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8167 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8168 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8169 | }; |
| 8170 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8171 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8172 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8173 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8174 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8175 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8176 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8177 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8178 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8179 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8180 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8181 | |
| 8182 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8183 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8184 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8185 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8186 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8187 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8188 | }; |
| 8189 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8190 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8191 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8192 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8193 | // Negotiate SPDY to the proxy |
| 8194 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8195 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8197 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8198 | auto trans = |
| 8199 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8200 | TestCompletionCallback callback; |
| 8201 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8202 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8203 | |
| 8204 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8205 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8206 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8207 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8208 | auto push_trans = |
| 8209 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8210 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8211 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8212 | |
| 8213 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8214 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8215 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8216 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8217 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8218 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8219 | |
| 8220 | EXPECT_EQ(200, response->headers->response_code()); |
| 8221 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8222 | |
| 8223 | std::string response_data; |
| 8224 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8225 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8226 | EXPECT_EQ("hello!", response_data); |
| 8227 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8228 | LoadTimingInfo load_timing_info; |
| 8229 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8230 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8231 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8232 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8233 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8234 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8235 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8236 | |
| 8237 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8238 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8239 | EXPECT_EQ("pushed", response_data); |
| 8240 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8241 | LoadTimingInfo push_load_timing_info; |
| 8242 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8243 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8244 | // The transactions should share a socket ID, despite being for different |
| 8245 | // origins. |
| 8246 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8247 | push_load_timing_info.socket_log_id); |
| 8248 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8249 | trans.reset(); |
| 8250 | push_trans.reset(); |
| 8251 | session->CloseAllConnections(); |
| 8252 | } |
| 8253 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8254 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8255 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8256 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8257 | auto proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8258 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8259 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8260 | HttpRequestInfo request; |
| 8261 | |
| 8262 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8263 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8264 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8265 | session_deps_.proxy_service = |
| 8266 | ProxyService::CreateFixed("https://myproxy:443"); |
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(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8269 | |
| 8270 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8271 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8272 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8273 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8274 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8275 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8276 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8277 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8278 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8279 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8280 | |
| 8281 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8282 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8283 | }; |
| 8284 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8285 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8286 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8287 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8288 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8289 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8290 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8291 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8292 | |
| 8293 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8294 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8295 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8296 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8297 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8298 | }; |
| 8299 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8300 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8301 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8302 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8303 | // Negotiate SPDY to the proxy |
| 8304 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8305 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8306 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8307 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8308 | auto trans = |
| 8309 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8310 | TestCompletionCallback callback; |
| 8311 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8312 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8313 | |
| 8314 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8315 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8316 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8317 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8318 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8319 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8320 | |
| 8321 | EXPECT_EQ(200, response->headers->response_code()); |
| 8322 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8323 | |
| 8324 | std::string response_data; |
| 8325 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8326 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8327 | EXPECT_EQ("hello!", response_data); |
| 8328 | |
| 8329 | trans.reset(); |
| 8330 | session->CloseAllConnections(); |
| 8331 | } |
| 8332 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8333 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8334 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8335 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8336 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8337 | auto proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8338 | proxy_delegate->set_trusted_spdy_proxy( |
| 8339 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8340 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8341 | HttpRequestInfo request; |
| 8342 | |
| 8343 | request.method = "GET"; |
| 8344 | request.url = GURL("http://www.example.org/"); |
| 8345 | |
| 8346 | // Configure against https proxy server "myproxy:70". |
| 8347 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8348 | BoundTestNetLog log; |
| 8349 | session_deps_.net_log = log.bound().net_log(); |
| 8350 | |
| 8351 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8352 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8353 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8354 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8355 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8356 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8357 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8358 | SpdySerializedFrame stream2_priority( |
| 8359 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8360 | |
| 8361 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8362 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8363 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8364 | }; |
| 8365 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8366 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8367 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8368 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8369 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8370 | nullptr, 0, 2, 1, "https://myproxy:70/foo.dat")); |
| 8371 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8372 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8373 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8374 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8375 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8376 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8377 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8378 | |
| 8379 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8380 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8381 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8382 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8383 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8384 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8385 | }; |
| 8386 | |
| 8387 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8388 | arraysize(spdy_writes)); |
| 8389 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8390 | // Negotiate SPDY to the proxy |
| 8391 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8392 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8393 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8394 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8395 | auto trans = |
| 8396 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8397 | TestCompletionCallback callback; |
| 8398 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8399 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8400 | |
| 8401 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8402 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8403 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8404 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8405 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8406 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8407 | |
| 8408 | EXPECT_EQ(200, response->headers->response_code()); |
| 8409 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8410 | |
| 8411 | std::string response_data; |
| 8412 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8413 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8414 | EXPECT_EQ("hello!", response_data); |
| 8415 | |
| 8416 | trans.reset(); |
| 8417 | session->CloseAllConnections(); |
| 8418 | } |
| 8419 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8420 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8421 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8422 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8423 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8424 | |
| 8425 | HttpRequestInfo request; |
| 8426 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8427 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8428 | |
| 8429 | // Attempt to fetch the URL from a server with a bad cert |
| 8430 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8431 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8432 | "Host: www.example.org:443\r\n" |
| 8433 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8434 | }; |
| 8435 | |
| 8436 | MockRead bad_cert_reads[] = { |
| 8437 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8438 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8439 | }; |
| 8440 | |
| 8441 | // Attempt to fetch the URL with a good cert |
| 8442 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8443 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8444 | "Host: www.example.org:443\r\n" |
| 8445 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8446 | MockWrite("GET / HTTP/1.1\r\n" |
| 8447 | "Host: www.example.org\r\n" |
| 8448 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8449 | }; |
| 8450 | |
| 8451 | MockRead good_cert_reads[] = { |
| 8452 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8453 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8454 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8455 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8456 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8457 | }; |
| 8458 | |
| 8459 | StaticSocketDataProvider ssl_bad_certificate( |
| 8460 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8461 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8462 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8463 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8464 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8465 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8466 | |
| 8467 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8469 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8470 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8471 | |
| 8472 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8474 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8475 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8476 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8477 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8478 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8479 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8480 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8481 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8482 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8483 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8484 | |
| 8485 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8486 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8488 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8490 | |
| 8491 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8492 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8493 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8494 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8495 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8496 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8497 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8498 | } |
| 8499 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8500 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8501 | HttpRequestInfo request; |
| 8502 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8503 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8504 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8505 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8506 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8507 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8508 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8509 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8510 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8511 | MockWrite( |
| 8512 | "GET / HTTP/1.1\r\n" |
| 8513 | "Host: www.example.org\r\n" |
| 8514 | "Connection: keep-alive\r\n" |
| 8515 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8516 | }; |
| 8517 | |
| 8518 | // Lastly, the server responds with the actual content. |
| 8519 | MockRead data_reads[] = { |
| 8520 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8521 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8522 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8523 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8524 | }; |
| 8525 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8526 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8527 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8528 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8529 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8530 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8531 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8532 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8533 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8534 | |
| 8535 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8536 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8537 | } |
| 8538 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8539 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8540 | HttpRequestInfo request; |
| 8541 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8542 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8543 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8544 | "Chromium Ultra Awesome X Edition"); |
| 8545 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8546 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8547 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8548 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8549 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8550 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8551 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8552 | "Host: www.example.org:443\r\n" |
| 8553 | "Proxy-Connection: keep-alive\r\n" |
| 8554 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8555 | }; |
| 8556 | MockRead data_reads[] = { |
| 8557 | // Return an error, so the transaction stops here (this test isn't |
| 8558 | // interested in the rest). |
| 8559 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8560 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8561 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8562 | }; |
| 8563 | |
| 8564 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8565 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8566 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8567 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8568 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8569 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8570 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8571 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8572 | |
| 8573 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8574 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8575 | } |
| 8576 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8577 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8578 | HttpRequestInfo request; |
| 8579 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8580 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8581 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8582 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8583 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8584 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8585 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8586 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8587 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8588 | MockWrite( |
| 8589 | "GET / HTTP/1.1\r\n" |
| 8590 | "Host: www.example.org\r\n" |
| 8591 | "Connection: keep-alive\r\n" |
| 8592 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8593 | }; |
| 8594 | |
| 8595 | // Lastly, the server responds with the actual content. |
| 8596 | MockRead data_reads[] = { |
| 8597 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8598 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8599 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8600 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8601 | }; |
| 8602 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8603 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8604 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8605 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8606 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8607 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8608 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8609 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8610 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8611 | |
| 8612 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8613 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8614 | } |
| 8615 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8616 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8617 | HttpRequestInfo request; |
| 8618 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8619 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8620 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8621 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8622 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8623 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8624 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8625 | MockWrite( |
| 8626 | "POST / HTTP/1.1\r\n" |
| 8627 | "Host: www.example.org\r\n" |
| 8628 | "Connection: keep-alive\r\n" |
| 8629 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8630 | }; |
| 8631 | |
| 8632 | // Lastly, the server responds with the actual content. |
| 8633 | MockRead data_reads[] = { |
| 8634 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8635 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8636 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8637 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8638 | }; |
| 8639 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8640 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8641 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8642 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8643 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8644 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8645 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8646 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8648 | |
| 8649 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8650 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8651 | } |
| 8652 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8653 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8654 | HttpRequestInfo request; |
| 8655 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8656 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8657 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8659 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8660 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8661 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8662 | MockWrite( |
| 8663 | "PUT / HTTP/1.1\r\n" |
| 8664 | "Host: www.example.org\r\n" |
| 8665 | "Connection: keep-alive\r\n" |
| 8666 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8667 | }; |
| 8668 | |
| 8669 | // Lastly, the server responds with the actual content. |
| 8670 | MockRead data_reads[] = { |
| 8671 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8672 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8673 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8674 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8675 | }; |
| 8676 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8677 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8678 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8679 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8680 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8681 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8682 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8683 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8684 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8685 | |
| 8686 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8687 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8688 | } |
| 8689 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8690 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8691 | HttpRequestInfo request; |
| 8692 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8693 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8694 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8695 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8696 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8697 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8698 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8699 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8700 | "Host: www.example.org\r\n" |
| 8701 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8702 | }; |
| 8703 | |
| 8704 | // Lastly, the server responds with the actual content. |
| 8705 | MockRead data_reads[] = { |
| 8706 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8707 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8708 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8709 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8710 | }; |
| 8711 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8712 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8713 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8714 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8715 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8716 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8717 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8718 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8719 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8720 | |
| 8721 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8722 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8723 | } |
| 8724 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8725 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8726 | HttpRequestInfo request; |
| 8727 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8728 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8729 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8730 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8732 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8733 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8734 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8735 | MockWrite( |
| 8736 | "GET / HTTP/1.1\r\n" |
| 8737 | "Host: www.example.org\r\n" |
| 8738 | "Connection: keep-alive\r\n" |
| 8739 | "Pragma: no-cache\r\n" |
| 8740 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8741 | }; |
| 8742 | |
| 8743 | // Lastly, the server responds with the actual content. |
| 8744 | MockRead data_reads[] = { |
| 8745 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8746 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8747 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8748 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8749 | }; |
| 8750 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8751 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8752 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8753 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8754 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8755 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8756 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8757 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8758 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8759 | |
| 8760 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8761 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8762 | } |
| 8763 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8764 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8765 | HttpRequestInfo request; |
| 8766 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8767 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8768 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8769 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8770 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8771 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8772 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8773 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8774 | MockWrite( |
| 8775 | "GET / HTTP/1.1\r\n" |
| 8776 | "Host: www.example.org\r\n" |
| 8777 | "Connection: keep-alive\r\n" |
| 8778 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8779 | }; |
| 8780 | |
| 8781 | // Lastly, the server responds with the actual content. |
| 8782 | MockRead data_reads[] = { |
| 8783 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8784 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8785 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8786 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8787 | }; |
| 8788 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8789 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8790 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8791 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8792 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8793 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8794 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8795 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8796 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8797 | |
| 8798 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8799 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8800 | } |
| 8801 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8802 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8803 | HttpRequestInfo request; |
| 8804 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8805 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8806 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8807 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8808 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8809 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8810 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8811 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8812 | MockWrite( |
| 8813 | "GET / HTTP/1.1\r\n" |
| 8814 | "Host: www.example.org\r\n" |
| 8815 | "Connection: keep-alive\r\n" |
| 8816 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8817 | }; |
| 8818 | |
| 8819 | // Lastly, the server responds with the actual content. |
| 8820 | MockRead data_reads[] = { |
| 8821 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8822 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8823 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8824 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8825 | }; |
| 8826 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8827 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8828 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8829 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8831 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8832 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8833 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8834 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8835 | |
| 8836 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8837 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8838 | } |
| 8839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8840 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8841 | HttpRequestInfo request; |
| 8842 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8843 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8844 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8845 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8846 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8847 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8848 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8849 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8850 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8851 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8852 | MockWrite( |
| 8853 | "GET / HTTP/1.1\r\n" |
| 8854 | "Host: www.example.org\r\n" |
| 8855 | "Connection: keep-alive\r\n" |
| 8856 | "referer: www.foo.com\r\n" |
| 8857 | "hEllo: Kitty\r\n" |
| 8858 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8859 | }; |
| 8860 | |
| 8861 | // Lastly, the server responds with the actual content. |
| 8862 | MockRead data_reads[] = { |
| 8863 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8864 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8865 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8866 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8867 | }; |
| 8868 | |
| 8869 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8870 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8871 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8872 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8873 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8874 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8875 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8876 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8877 | |
| 8878 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8879 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8880 | } |
| 8881 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8882 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8883 | HttpRequestInfo request; |
| 8884 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8885 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8886 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8887 | session_deps_.proxy_service = |
| 8888 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8889 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8890 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8891 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8892 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8893 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8894 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8895 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8896 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8897 | |
| 8898 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8899 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8900 | MockWrite( |
| 8901 | "GET / HTTP/1.1\r\n" |
| 8902 | "Host: www.example.org\r\n" |
| 8903 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8904 | |
| 8905 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8906 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8907 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8908 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8909 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8910 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8911 | }; |
| 8912 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8913 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8914 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8915 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8916 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8917 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8918 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8919 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8921 | |
| 8922 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8923 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8925 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8926 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8927 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8928 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8929 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8930 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8931 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8932 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8933 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8934 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8935 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8936 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8937 | EXPECT_EQ("Payload", response_text); |
| 8938 | } |
| 8939 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8940 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8941 | HttpRequestInfo request; |
| 8942 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8943 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8944 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8945 | session_deps_.proxy_service = |
| 8946 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8947 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8948 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8949 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8950 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8951 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8952 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8953 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8954 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8955 | |
| 8956 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8957 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8958 | arraysize(write_buffer)), |
| 8959 | MockWrite( |
| 8960 | "GET / HTTP/1.1\r\n" |
| 8961 | "Host: www.example.org\r\n" |
| 8962 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8963 | |
| 8964 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8965 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8966 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8967 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8968 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8969 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8970 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8971 | }; |
| 8972 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8973 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8974 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8975 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8976 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8977 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8978 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8980 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8981 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8982 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8984 | |
| 8985 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8986 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8987 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8988 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8989 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8990 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8991 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8992 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8993 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8994 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8995 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8996 | |
| 8997 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8998 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8999 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9000 | EXPECT_EQ("Payload", response_text); |
| 9001 | } |
| 9002 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9003 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9004 | HttpRequestInfo request; |
| 9005 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9006 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9007 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9008 | session_deps_.proxy_service = |
| 9009 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9010 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9011 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9012 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9013 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9014 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9015 | |
| 9016 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9017 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9018 | |
| 9019 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9020 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9021 | MockWrite( |
| 9022 | "GET / HTTP/1.1\r\n" |
| 9023 | "Host: www.example.org\r\n" |
| 9024 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9025 | |
| 9026 | MockRead data_reads[] = { |
| 9027 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9028 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9029 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9030 | MockRead("Payload"), |
| 9031 | MockRead(SYNCHRONOUS, OK) |
| 9032 | }; |
| 9033 | |
| 9034 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9035 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9036 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9037 | |
| 9038 | TestCompletionCallback callback; |
| 9039 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9040 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9041 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9042 | |
| 9043 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9044 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9045 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9046 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9047 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9048 | |
| 9049 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9050 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9051 | TestLoadTimingNotReused(load_timing_info, |
| 9052 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9053 | |
| 9054 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9055 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9056 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9057 | EXPECT_EQ("Payload", response_text); |
| 9058 | } |
| 9059 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9060 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9061 | HttpRequestInfo request; |
| 9062 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9063 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9064 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9065 | session_deps_.proxy_service = |
| 9066 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9067 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9068 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9069 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9070 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9071 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9072 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9073 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9074 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9075 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9076 | 0x05, // Version |
| 9077 | 0x01, // Command (CONNECT) |
| 9078 | 0x00, // Reserved. |
| 9079 | 0x03, // Address type (DOMAINNAME). |
| 9080 | 0x0F, // Length of domain (15) |
| 9081 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9082 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9083 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9084 | const char kSOCKS5OkResponse[] = |
| 9085 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9086 | |
| 9087 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9088 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9089 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9090 | MockWrite( |
| 9091 | "GET / HTTP/1.1\r\n" |
| 9092 | "Host: www.example.org\r\n" |
| 9093 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9094 | |
| 9095 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9096 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9097 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9098 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9099 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9100 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9101 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9102 | }; |
| 9103 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9104 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9105 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9106 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9107 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9108 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9109 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9110 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9111 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9112 | |
| 9113 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9114 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9116 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9117 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9118 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9119 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9120 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9121 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9122 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9123 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9124 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9125 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9126 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9127 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9128 | EXPECT_EQ("Payload", response_text); |
| 9129 | } |
| 9130 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9131 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9132 | HttpRequestInfo request; |
| 9133 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9134 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9135 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9136 | session_deps_.proxy_service = |
| 9137 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9138 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9139 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9140 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9141 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9142 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9143 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9144 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9145 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9146 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9147 | 0x05, // Version |
| 9148 | 0x01, // Command (CONNECT) |
| 9149 | 0x00, // Reserved. |
| 9150 | 0x03, // Address type (DOMAINNAME). |
| 9151 | 0x0F, // Length of domain (15) |
| 9152 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9153 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9154 | }; |
| 9155 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9156 | const char kSOCKS5OkResponse[] = |
| 9157 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9158 | |
| 9159 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9160 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9161 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9162 | arraysize(kSOCKS5OkRequest)), |
| 9163 | MockWrite( |
| 9164 | "GET / HTTP/1.1\r\n" |
| 9165 | "Host: www.example.org\r\n" |
| 9166 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9167 | |
| 9168 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9169 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9170 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9171 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9172 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9173 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9174 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9175 | }; |
| 9176 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9177 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9178 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9179 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9180 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9181 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9182 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9183 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9184 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9185 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9186 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9187 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9188 | |
| 9189 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9190 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9192 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9193 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9194 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9195 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9196 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9197 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9198 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9199 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9200 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9201 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9202 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9203 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9204 | EXPECT_EQ("Payload", response_text); |
| 9205 | } |
| 9206 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9207 | namespace { |
| 9208 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9209 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9210 | |
| 9211 | struct GroupNameTest { |
| 9212 | std::string proxy_server; |
| 9213 | std::string url; |
| 9214 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9215 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9216 | }; |
| 9217 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9218 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9219 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9220 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9221 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9222 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9223 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9224 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9225 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9226 | http_server_properties->SetAlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9227 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9228 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9229 | |
| 9230 | return session; |
| 9231 | } |
| 9232 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9233 | int GroupNameTransactionHelper(const std::string& url, |
| 9234 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9235 | HttpRequestInfo request; |
| 9236 | request.method = "GET"; |
| 9237 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9238 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9239 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9241 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9242 | |
| 9243 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9244 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9245 | } |
| 9246 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9247 | } // namespace |
| 9248 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9249 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9250 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9251 | { |
| 9252 | "", // unused |
| 9253 | "http://www.example.org/direct", |
| 9254 | "www.example.org:80", |
| 9255 | false, |
| 9256 | }, |
| 9257 | { |
| 9258 | "", // unused |
| 9259 | "http://[2001:1418:13:1::25]/direct", |
| 9260 | "[2001:1418:13:1::25]:80", |
| 9261 | false, |
| 9262 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9263 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9264 | // SSL Tests |
| 9265 | { |
| 9266 | "", // unused |
| 9267 | "https://www.example.org/direct_ssl", |
| 9268 | "ssl/www.example.org:443", |
| 9269 | true, |
| 9270 | }, |
| 9271 | { |
| 9272 | "", // unused |
| 9273 | "https://[2001:1418:13:1::25]/direct", |
| 9274 | "ssl/[2001:1418:13:1::25]:443", |
| 9275 | true, |
| 9276 | }, |
| 9277 | { |
| 9278 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9279 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9280 | "ssl/host.with.alternate:443", |
| 9281 | true, |
| 9282 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9283 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9284 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9285 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9286 | session_deps_.proxy_service = |
| 9287 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9288 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9289 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9290 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9291 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9292 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9293 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9294 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9295 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
| 9296 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9297 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9298 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9299 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9300 | |
| 9301 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9302 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9303 | if (tests[i].ssl) |
| 9304 | EXPECT_EQ(tests[i].expected_group_name, |
| 9305 | ssl_conn_pool->last_group_name_received()); |
| 9306 | else |
| 9307 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9308 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9309 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9310 | } |
| 9311 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9312 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9313 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9314 | { |
| 9315 | "http_proxy", |
| 9316 | "http://www.example.org/http_proxy_normal", |
| 9317 | "www.example.org:80", |
| 9318 | false, |
| 9319 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9320 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9321 | // SSL Tests |
| 9322 | { |
| 9323 | "http_proxy", |
| 9324 | "https://www.example.org/http_connect_ssl", |
| 9325 | "ssl/www.example.org:443", |
| 9326 | true, |
| 9327 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9328 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9329 | { |
| 9330 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9331 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9332 | "ssl/host.with.alternate:443", |
| 9333 | true, |
| 9334 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9335 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9336 | { |
| 9337 | "http_proxy", |
| 9338 | "ftp://ftp.google.com/http_proxy_normal", |
| 9339 | "ftp/ftp.google.com:21", |
| 9340 | false, |
| 9341 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9342 | }; |
| 9343 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9344 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9345 | session_deps_.proxy_service = |
| 9346 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9347 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9348 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9349 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9350 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9351 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9352 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9353 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9354 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9355 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9356 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9357 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9358 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9359 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9360 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9361 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9362 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9363 | |
| 9364 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9365 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9366 | if (tests[i].ssl) |
| 9367 | EXPECT_EQ(tests[i].expected_group_name, |
| 9368 | ssl_conn_pool->last_group_name_received()); |
| 9369 | else |
| 9370 | EXPECT_EQ(tests[i].expected_group_name, |
| 9371 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9372 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9373 | } |
| 9374 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9375 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9376 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9377 | { |
| 9378 | "socks4://socks_proxy:1080", |
| 9379 | "http://www.example.org/socks4_direct", |
| 9380 | "socks4/www.example.org:80", |
| 9381 | false, |
| 9382 | }, |
| 9383 | { |
| 9384 | "socks5://socks_proxy:1080", |
| 9385 | "http://www.example.org/socks5_direct", |
| 9386 | "socks5/www.example.org:80", |
| 9387 | false, |
| 9388 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9389 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9390 | // SSL Tests |
| 9391 | { |
| 9392 | "socks4://socks_proxy:1080", |
| 9393 | "https://www.example.org/socks4_ssl", |
| 9394 | "socks4/ssl/www.example.org:443", |
| 9395 | true, |
| 9396 | }, |
| 9397 | { |
| 9398 | "socks5://socks_proxy:1080", |
| 9399 | "https://www.example.org/socks5_ssl", |
| 9400 | "socks5/ssl/www.example.org:443", |
| 9401 | true, |
| 9402 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9403 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9404 | { |
| 9405 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9406 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9407 | "socks4/ssl/host.with.alternate:443", |
| 9408 | true, |
| 9409 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9410 | }; |
| 9411 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9412 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9413 | session_deps_.proxy_service = |
| 9414 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9415 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9416 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9417 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9418 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9419 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9420 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9421 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9422 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9423 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9424 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9425 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9426 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 9427 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 9428 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9429 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9430 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9431 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9432 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9433 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9434 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9435 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9436 | if (tests[i].ssl) |
| 9437 | EXPECT_EQ(tests[i].expected_group_name, |
| 9438 | ssl_conn_pool->last_group_name_received()); |
| 9439 | else |
| 9440 | EXPECT_EQ(tests[i].expected_group_name, |
| 9441 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9442 | } |
| 9443 | } |
| 9444 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9445 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9446 | HttpRequestInfo request; |
| 9447 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9448 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9449 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9450 | session_deps_.proxy_service = |
| 9451 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9452 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9453 | // This simulates failure resolving all hostnames; that means we will fail |
| 9454 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9455 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9456 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9457 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9458 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9459 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9460 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9461 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9462 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9464 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9465 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9466 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9467 | } |
| 9468 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9469 | // Base test to make sure that when the load flags for a request specify to |
| 9470 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9471 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9472 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9473 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9474 | HttpRequestInfo request_info; |
| 9475 | request_info.method = "GET"; |
| 9476 | request_info.load_flags = load_flags; |
| 9477 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9478 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9479 | // Select a host resolver that does caching. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9480 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9481 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9482 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9483 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9484 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9485 | // 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] | 9486 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9487 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9488 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9489 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9490 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9491 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9492 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9493 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9494 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9495 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9496 | |
| 9497 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9498 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9499 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9500 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9501 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9502 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9503 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9504 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9505 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9506 | // 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] | 9507 | // we can tell if the next lookup hit the cache, or the "network". |
| 9508 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9509 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9510 | |
| 9511 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9512 | // 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] | 9513 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9514 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9515 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9516 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9517 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9518 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9519 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9520 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9521 | |
| 9522 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9523 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9524 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9525 | } |
| 9526 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9527 | // There are multiple load flags that should trigger the host cache bypass. |
| 9528 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9529 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9530 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9531 | } |
| 9532 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9533 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9534 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9535 | } |
| 9536 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9537 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9538 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9539 | } |
| 9540 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9541 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9542 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9543 | HttpRequestInfo request; |
| 9544 | request.method = "GET"; |
| 9545 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9546 | |
| 9547 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9548 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9549 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9550 | StaticSocketDataProvider data(NULL, 0, |
| 9551 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9552 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9553 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9554 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9555 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9556 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9557 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9558 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9559 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9560 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9561 | |
| 9562 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9563 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9564 | |
| 9565 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9566 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9567 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9568 | } |
| 9569 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9570 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9571 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9572 | HttpRequestInfo request; |
| 9573 | request.method = "GET"; |
| 9574 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9575 | |
| 9576 | MockRead data_reads[] = { |
| 9577 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9578 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9579 | }; |
| 9580 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9581 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9582 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9583 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9584 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9585 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9587 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9588 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9589 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9590 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9591 | |
| 9592 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9593 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9595 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9596 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9597 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9598 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9599 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9600 | |
| 9601 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9602 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9603 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9604 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9605 | |
| 9606 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9607 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9608 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9609 | } |
| 9610 | |
| 9611 | // Make sure that a dropped connection while draining the body for auth |
| 9612 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9613 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9614 | HttpRequestInfo request; |
| 9615 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9616 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9617 | |
| 9618 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9619 | MockWrite( |
| 9620 | "GET / HTTP/1.1\r\n" |
| 9621 | "Host: www.example.org\r\n" |
| 9622 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9623 | }; |
| 9624 | |
| 9625 | MockRead data_reads1[] = { |
| 9626 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9627 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9628 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9629 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9630 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9631 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9632 | }; |
| 9633 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9634 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9635 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9636 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9637 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9638 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9639 | // be issuing -- the final header line contains the credentials. |
| 9640 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9641 | MockWrite( |
| 9642 | "GET / HTTP/1.1\r\n" |
| 9643 | "Host: www.example.org\r\n" |
| 9644 | "Connection: keep-alive\r\n" |
| 9645 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9646 | }; |
| 9647 | |
| 9648 | // Lastly, the server responds with the actual content. |
| 9649 | MockRead data_reads2[] = { |
| 9650 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9651 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9652 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9653 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9654 | }; |
| 9655 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9656 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9657 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9658 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9660 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9661 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9662 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9663 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9664 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9665 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9666 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9667 | |
| 9668 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9669 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9670 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9671 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9672 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9673 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9674 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9675 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9676 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9677 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9679 | |
| 9680 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9681 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9683 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9684 | ASSERT_TRUE(response); |
| 9685 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9686 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9687 | } |
| 9688 | |
| 9689 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9690 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9691 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9692 | |
| 9693 | HttpRequestInfo request; |
| 9694 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9695 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9696 | |
| 9697 | MockRead proxy_reads[] = { |
| 9698 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9699 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9700 | }; |
| 9701 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9702 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9703 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9704 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9705 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9706 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9707 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9708 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9709 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9710 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9711 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9713 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9714 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9715 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9716 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9717 | |
| 9718 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9719 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9720 | } |
| 9721 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9722 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9723 | HttpRequestInfo request; |
| 9724 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9725 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9726 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9728 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9729 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9730 | MockRead data_reads[] = { |
| 9731 | 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] | 9732 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9733 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9734 | |
| 9735 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9736 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9738 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9739 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9740 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9741 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9742 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9743 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9744 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9745 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9746 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9747 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9748 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9749 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9750 | |
| 9751 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9752 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9753 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9754 | } |
| 9755 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9756 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9757 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9758 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9759 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9760 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9761 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9762 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9763 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9764 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9765 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9766 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9767 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9768 | |
| 9769 | HttpRequestInfo request; |
| 9770 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9771 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9772 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9773 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9774 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9775 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9776 | |
| 9777 | MockRead data_reads[] = { |
| 9778 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9779 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9780 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9781 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9782 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9783 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9784 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9785 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9786 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9787 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9788 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9789 | |
| 9790 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9791 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9792 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9793 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9794 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9795 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 9796 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9797 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9798 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9799 | } |
| 9800 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9801 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9802 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9803 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9804 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 9805 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 9806 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 9807 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9808 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9809 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9810 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9811 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9812 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9813 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9814 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9815 | |
| 9816 | HttpRequestInfo request; |
| 9817 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9818 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9819 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9820 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9821 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9822 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9823 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9824 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9825 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9826 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9827 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9828 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9829 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9830 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9831 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9832 | |
| 9833 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9834 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9835 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9836 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9837 | } |
| 9838 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9839 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9840 | class FakeUploadElementReader : public UploadElementReader { |
| 9841 | public: |
| 9842 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9843 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9844 | |
| 9845 | const CompletionCallback& callback() const { return callback_; } |
| 9846 | |
| 9847 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9848 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9849 | callback_ = callback; |
| 9850 | return ERR_IO_PENDING; |
| 9851 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9852 | uint64_t GetContentLength() const override { return 0; } |
| 9853 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9854 | int Read(IOBuffer* buf, |
| 9855 | int buf_length, |
| 9856 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9857 | return ERR_FAILED; |
| 9858 | } |
| 9859 | |
| 9860 | private: |
| 9861 | CompletionCallback callback_; |
| 9862 | }; |
| 9863 | |
| 9864 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9865 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9866 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9867 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9868 | |
| 9869 | HttpRequestInfo request; |
| 9870 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9871 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9872 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9873 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9874 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9875 | auto trans = |
| 9876 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9877 | |
| 9878 | StaticSocketDataProvider data; |
| 9879 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9880 | |
| 9881 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9882 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9883 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9884 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9885 | |
| 9886 | // Transaction is pending on request body initialization. |
| 9887 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9888 | |
| 9889 | // Return Init()'s result after the transaction gets destroyed. |
| 9890 | trans.reset(); |
| 9891 | fake_reader->callback().Run(OK); // Should not crash. |
| 9892 | } |
| 9893 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9894 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9895 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9896 | HttpRequestInfo request; |
| 9897 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9898 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9899 | |
| 9900 | // First transaction will request a resource and receive a Basic challenge |
| 9901 | // with realm="first_realm". |
| 9902 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9903 | MockWrite( |
| 9904 | "GET / HTTP/1.1\r\n" |
| 9905 | "Host: www.example.org\r\n" |
| 9906 | "Connection: keep-alive\r\n" |
| 9907 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9908 | }; |
| 9909 | MockRead data_reads1[] = { |
| 9910 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9911 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9912 | "\r\n"), |
| 9913 | }; |
| 9914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9915 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9916 | // for first_realm. The server will reject and provide a challenge with |
| 9917 | // second_realm. |
| 9918 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9919 | MockWrite( |
| 9920 | "GET / HTTP/1.1\r\n" |
| 9921 | "Host: www.example.org\r\n" |
| 9922 | "Connection: keep-alive\r\n" |
| 9923 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9924 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9925 | }; |
| 9926 | MockRead data_reads2[] = { |
| 9927 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9928 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9929 | "\r\n"), |
| 9930 | }; |
| 9931 | |
| 9932 | // This again fails, and goes back to first_realm. Make sure that the |
| 9933 | // entry is removed from cache. |
| 9934 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9935 | MockWrite( |
| 9936 | "GET / HTTP/1.1\r\n" |
| 9937 | "Host: www.example.org\r\n" |
| 9938 | "Connection: keep-alive\r\n" |
| 9939 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9940 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9941 | }; |
| 9942 | MockRead data_reads3[] = { |
| 9943 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9944 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9945 | "\r\n"), |
| 9946 | }; |
| 9947 | |
| 9948 | // Try one last time (with the correct password) and get the resource. |
| 9949 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9950 | MockWrite( |
| 9951 | "GET / HTTP/1.1\r\n" |
| 9952 | "Host: www.example.org\r\n" |
| 9953 | "Connection: keep-alive\r\n" |
| 9954 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9955 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9956 | }; |
| 9957 | MockRead data_reads4[] = { |
| 9958 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9959 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9960 | "Content-Length: 5\r\n" |
| 9961 | "\r\n" |
| 9962 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9963 | }; |
| 9964 | |
| 9965 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9966 | data_writes1, arraysize(data_writes1)); |
| 9967 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9968 | data_writes2, arraysize(data_writes2)); |
| 9969 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9970 | data_writes3, arraysize(data_writes3)); |
| 9971 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9972 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9973 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9974 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9975 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9976 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9977 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9978 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9979 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9980 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9981 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9982 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9983 | // Issue the first request with Authorize headers. There should be a |
| 9984 | // password prompt for first_realm waiting to be filled in after the |
| 9985 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9986 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9987 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9988 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9989 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9990 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9991 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9992 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9993 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9994 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9995 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9996 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9997 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9998 | |
| 9999 | // Issue the second request with an incorrect password. There should be a |
| 10000 | // password prompt for second_realm waiting to be filled in after the |
| 10001 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10002 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10003 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10004 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10005 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10006 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10007 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10008 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10009 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10010 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10011 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10012 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10013 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10014 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10015 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10016 | |
| 10017 | // Issue the third request with another incorrect password. There should be |
| 10018 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10019 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10020 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10021 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10022 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10023 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10024 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10025 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10026 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10027 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10028 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10029 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10030 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10031 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10032 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10033 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10034 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10035 | |
| 10036 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10037 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10038 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10039 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10040 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10041 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10042 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10043 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10044 | ASSERT_TRUE(response); |
| 10045 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10046 | } |
| 10047 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10048 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10049 | MockRead data_reads[] = { |
| 10050 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10051 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10052 | MockRead("\r\n"), |
| 10053 | MockRead("hello world"), |
| 10054 | MockRead(SYNCHRONOUS, OK), |
| 10055 | }; |
| 10056 | |
| 10057 | HttpRequestInfo request; |
| 10058 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10059 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10060 | |
| 10061 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10062 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10063 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10064 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10065 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10066 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10067 | TestCompletionCallback callback; |
| 10068 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10069 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10070 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10071 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10072 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10074 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10075 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10076 | HttpServerProperties* http_server_properties = |
| 10077 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10078 | EXPECT_TRUE( |
| 10079 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10080 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10081 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10082 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10083 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10084 | ASSERT_TRUE(response); |
| 10085 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10086 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10087 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10088 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10089 | |
| 10090 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10091 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10092 | EXPECT_EQ("hello world", response_data); |
| 10093 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10094 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10095 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10096 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10097 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 10098 | EXPECT_EQ(alternative_service, |
| 10099 | alternative_service_info_vector[0].alternative_service); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10100 | } |
| 10101 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10102 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10103 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10104 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10105 | MockRead data_reads[] = { |
| 10106 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10107 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10108 | MockRead("\r\n"), |
| 10109 | MockRead("hello world"), |
| 10110 | MockRead(SYNCHRONOUS, OK), |
| 10111 | }; |
| 10112 | |
| 10113 | HttpRequestInfo request; |
| 10114 | request.method = "GET"; |
| 10115 | request.url = GURL("http://www.example.org/"); |
| 10116 | request.load_flags = 0; |
| 10117 | |
| 10118 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10119 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10120 | |
| 10121 | TestCompletionCallback callback; |
| 10122 | |
| 10123 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10124 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10125 | |
| 10126 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10127 | HttpServerProperties* http_server_properties = |
| 10128 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10129 | EXPECT_TRUE( |
| 10130 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10131 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10132 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10133 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10134 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10135 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10136 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10137 | ASSERT_TRUE(response); |
| 10138 | ASSERT_TRUE(response->headers); |
| 10139 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10140 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10141 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10142 | |
| 10143 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10144 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10145 | EXPECT_EQ("hello world", response_data); |
| 10146 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10147 | EXPECT_TRUE( |
| 10148 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10149 | } |
| 10150 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10151 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10152 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10153 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10154 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10155 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10156 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10157 | HttpRequestInfo request; |
| 10158 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10159 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10160 | request.load_flags = 0; |
| 10161 | |
| 10162 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10163 | StaticSocketDataProvider first_data; |
| 10164 | first_data.set_connect_data(mock_connect); |
| 10165 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10166 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10167 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10168 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10169 | |
| 10170 | MockRead data_reads[] = { |
| 10171 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10172 | MockRead(ASYNC, OK), |
| 10173 | }; |
| 10174 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10175 | 0); |
| 10176 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10177 | |
| 10178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10179 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10180 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10181 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10182 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10183 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10184 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10185 | http_server_properties->SetAlternativeService( |
| 10186 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10187 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10188 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10189 | TestCompletionCallback callback; |
| 10190 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10191 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10192 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10193 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10194 | } |
| 10195 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10196 | // Regression test for https://crbug.com/615497: |
| 10197 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10198 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10199 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10200 | HttpRequestInfo request; |
| 10201 | request.method = "GET"; |
| 10202 | request.url = GURL("http://www.example.org/"); |
| 10203 | request.load_flags = 0; |
| 10204 | |
| 10205 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10206 | StaticSocketDataProvider first_data; |
| 10207 | first_data.set_connect_data(mock_connect); |
| 10208 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10209 | |
| 10210 | MockRead data_reads[] = { |
| 10211 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10212 | MockRead(ASYNC, OK), |
| 10213 | }; |
| 10214 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10215 | 0); |
| 10216 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10217 | |
| 10218 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10219 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10220 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10221 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10222 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10223 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10224 | http_server_properties->SetAlternativeService( |
| 10225 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10226 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10227 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10228 | TestCompletionCallback callback; |
| 10229 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10230 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10231 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10232 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10233 | } |
| 10234 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10235 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10236 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10237 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10238 | HttpServerProperties* http_server_properties = |
| 10239 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10240 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10241 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10242 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10243 | http_server_properties->SetAlternativeService( |
| 10244 | test_server, alternative_service, expiration); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10245 | EXPECT_EQ( |
| 10246 | 1u, |
| 10247 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10248 | |
| 10249 | // Send a clear header. |
| 10250 | MockRead data_reads[] = { |
| 10251 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10252 | MockRead("Alt-Svc: clear\r\n"), |
| 10253 | MockRead("\r\n"), |
| 10254 | MockRead("hello world"), |
| 10255 | MockRead(SYNCHRONOUS, OK), |
| 10256 | }; |
| 10257 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10258 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10259 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10260 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10261 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10262 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10263 | HttpRequestInfo request; |
| 10264 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10265 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10266 | |
| 10267 | TestCompletionCallback callback; |
| 10268 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10269 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10270 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10271 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10272 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10273 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10274 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10275 | ASSERT_TRUE(response); |
| 10276 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10277 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10278 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10279 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10280 | |
| 10281 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10282 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10283 | EXPECT_EQ("hello world", response_data); |
| 10284 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10285 | EXPECT_TRUE( |
| 10286 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10287 | } |
| 10288 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10289 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10290 | MockRead data_reads[] = { |
| 10291 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10292 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10293 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10294 | MockRead("hello world"), |
| 10295 | MockRead(SYNCHRONOUS, OK), |
| 10296 | }; |
| 10297 | |
| 10298 | HttpRequestInfo request; |
| 10299 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10300 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10301 | |
| 10302 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10303 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10304 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10305 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10306 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10307 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10308 | TestCompletionCallback callback; |
| 10309 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10310 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10311 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10312 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10313 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10314 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10315 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10316 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10317 | HttpServerProperties* http_server_properties = |
| 10318 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10319 | EXPECT_TRUE( |
| 10320 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10321 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10322 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10323 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10324 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10325 | ASSERT_TRUE(response); |
| 10326 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10327 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10328 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10329 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10330 | |
| 10331 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10332 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10333 | EXPECT_EQ("hello world", response_data); |
| 10334 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10335 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10336 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10337 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 10338 | |
| 10339 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 10340 | EXPECT_EQ(alternative_service, |
| 10341 | alternative_service_info_vector[0].alternative_service); |
| 10342 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 10343 | 1234); |
| 10344 | EXPECT_EQ(alternative_service_2, |
| 10345 | alternative_service_info_vector[1].alternative_service); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10346 | } |
| 10347 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10348 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10349 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10350 | HostPortPair alternative("alternative.example.org", 443); |
| 10351 | std::string origin_url = "https://origin.example.org:443"; |
| 10352 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10353 | |
| 10354 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10355 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10356 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10357 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10358 | |
| 10359 | // HTTP/1.1 data for request. |
| 10360 | MockWrite http_writes[] = { |
| 10361 | MockWrite("GET / HTTP/1.1\r\n" |
| 10362 | "Host: alternative.example.org\r\n" |
| 10363 | "Connection: keep-alive\r\n\r\n"), |
| 10364 | }; |
| 10365 | |
| 10366 | MockRead http_reads[] = { |
| 10367 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10368 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10369 | "Content-Length: 40\r\n\r\n" |
| 10370 | "first HTTP/1.1 response from alternative"), |
| 10371 | }; |
| 10372 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10373 | http_writes, arraysize(http_writes)); |
| 10374 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10375 | |
| 10376 | StaticSocketDataProvider data_refused; |
| 10377 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10378 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10379 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10380 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10381 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10382 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10383 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10384 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10385 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10386 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10387 | expiration); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10388 | // Mark the QUIC alternative service as broken. |
| 10389 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10390 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10391 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10392 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10393 | request.method = "GET"; |
| 10394 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10395 | TestCompletionCallback callback; |
| 10396 | NetErrorDetails details; |
| 10397 | EXPECT_FALSE(details.quic_broken); |
| 10398 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10399 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10400 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10401 | EXPECT_TRUE(details.quic_broken); |
| 10402 | } |
| 10403 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10404 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10405 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10406 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10407 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10408 | std::string origin_url = "https://origin.example.org:443"; |
| 10409 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10410 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10411 | |
| 10412 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10413 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10414 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10415 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10416 | |
| 10417 | // HTTP/1.1 data for request. |
| 10418 | MockWrite http_writes[] = { |
| 10419 | MockWrite("GET / HTTP/1.1\r\n" |
| 10420 | "Host: alternative1.example.org\r\n" |
| 10421 | "Connection: keep-alive\r\n\r\n"), |
| 10422 | }; |
| 10423 | |
| 10424 | MockRead http_reads[] = { |
| 10425 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10426 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10427 | "Content-Length: 40\r\n\r\n" |
| 10428 | "first HTTP/1.1 response from alternative1"), |
| 10429 | }; |
| 10430 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10431 | http_writes, arraysize(http_writes)); |
| 10432 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10433 | |
| 10434 | StaticSocketDataProvider data_refused; |
| 10435 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10436 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10437 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10438 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10439 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10440 | session->http_server_properties(); |
| 10441 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10442 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10443 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10444 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10445 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10446 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10447 | AlternativeServiceInfo alternative_service_info1(alternative_service1, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10448 | expiration); |
| 10449 | alternative_service_info_vector.push_back(alternative_service_info1); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10450 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10451 | AlternativeServiceInfo alternative_service_info2(alternative_service2, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10452 | expiration); |
| 10453 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10454 | |
| 10455 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10456 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10457 | |
| 10458 | // Mark one of the QUIC alternative service as broken. |
| 10459 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10460 | EXPECT_EQ(2u, |
| 10461 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10462 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10463 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10464 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10465 | request.method = "GET"; |
| 10466 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10467 | TestCompletionCallback callback; |
| 10468 | NetErrorDetails details; |
| 10469 | EXPECT_FALSE(details.quic_broken); |
| 10470 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10471 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10472 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10473 | EXPECT_FALSE(details.quic_broken); |
| 10474 | } |
| 10475 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10476 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10477 | HttpRequestInfo request; |
| 10478 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10479 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10480 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10481 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10482 | StaticSocketDataProvider first_data; |
| 10483 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10484 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10485 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10486 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10487 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10488 | |
| 10489 | MockRead data_reads[] = { |
| 10490 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10491 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10492 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10493 | }; |
| 10494 | StaticSocketDataProvider second_data( |
| 10495 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10496 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10497 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10498 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10499 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10500 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10501 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10502 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10503 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10504 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10505 | const AlternativeService alternative_service( |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10506 | kProtoHTTP2, "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10507 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10508 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10509 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 10510 | expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10511 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10512 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10513 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10514 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10515 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10516 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10517 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10518 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10519 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10520 | ASSERT_TRUE(response); |
| 10521 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10522 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10523 | |
| 10524 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10525 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10526 | EXPECT_EQ("hello world", response_data); |
| 10527 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10528 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 10529 | http_server_properties->GetAlternativeServiceInfos(server); |
| 10530 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10531 | EXPECT_EQ(alternative_service, |
| 10532 | alternative_service_info_vector[0].alternative_service); |
| 10533 | EXPECT_TRUE( |
| 10534 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10535 | } |
| 10536 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10537 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10538 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10539 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10540 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10541 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10542 | HttpRequestInfo restricted_port_request; |
| 10543 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10544 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10545 | restricted_port_request.load_flags = 0; |
| 10546 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10547 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10548 | StaticSocketDataProvider first_data; |
| 10549 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10550 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10551 | |
| 10552 | MockRead data_reads[] = { |
| 10553 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10554 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10555 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10556 | }; |
| 10557 | StaticSocketDataProvider second_data( |
| 10558 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10559 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10560 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10561 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10562 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10563 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10564 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10565 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10566 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10567 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10568 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10569 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10570 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10571 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10572 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10573 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10574 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10575 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10576 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10577 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10578 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10579 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10580 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10581 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10582 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10583 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10584 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10585 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10586 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10587 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10588 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10589 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10590 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10591 | |
| 10592 | HttpRequestInfo restricted_port_request; |
| 10593 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10594 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10595 | restricted_port_request.load_flags = 0; |
| 10596 | |
| 10597 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10598 | StaticSocketDataProvider first_data; |
| 10599 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10600 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10601 | |
| 10602 | MockRead data_reads[] = { |
| 10603 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10604 | MockRead("hello world"), |
| 10605 | MockRead(ASYNC, OK), |
| 10606 | }; |
| 10607 | StaticSocketDataProvider second_data( |
| 10608 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10609 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10610 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10611 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10612 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10613 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10614 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10615 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10616 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10617 | session->http_server_properties(); |
| 10618 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10619 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10620 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10621 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10622 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10623 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10624 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10625 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10627 | TestCompletionCallback callback; |
| 10628 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10629 | EXPECT_EQ(ERR_IO_PENDING, |
| 10630 | trans.Start(&restricted_port_request, callback.callback(), |
| 10631 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10632 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10633 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10634 | } |
| 10635 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10636 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10637 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10638 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10639 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10640 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10641 | HttpRequestInfo restricted_port_request; |
| 10642 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10643 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10644 | restricted_port_request.load_flags = 0; |
| 10645 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10646 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10647 | StaticSocketDataProvider first_data; |
| 10648 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10649 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10650 | |
| 10651 | MockRead data_reads[] = { |
| 10652 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10653 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10654 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10655 | }; |
| 10656 | StaticSocketDataProvider second_data( |
| 10657 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10658 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10659 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10660 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10661 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10662 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10663 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10664 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10665 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10666 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10667 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10668 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10669 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10670 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10671 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10672 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10673 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10674 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10675 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10676 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10677 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10678 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10679 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10681 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10682 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10683 | } |
| 10684 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10685 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10686 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10687 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10688 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10689 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10690 | HttpRequestInfo unrestricted_port_request; |
| 10691 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10692 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10693 | unrestricted_port_request.load_flags = 0; |
| 10694 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10695 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10696 | StaticSocketDataProvider first_data; |
| 10697 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10698 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10699 | |
| 10700 | MockRead data_reads[] = { |
| 10701 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10702 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10703 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10704 | }; |
| 10705 | StaticSocketDataProvider second_data( |
| 10706 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10707 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10708 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10709 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10710 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10711 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10713 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10714 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10715 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10716 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10717 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10718 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10719 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10720 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10721 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10722 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10724 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10725 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10726 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10727 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10728 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10729 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10730 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10731 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10732 | } |
| 10733 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10734 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10735 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10736 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10737 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10738 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10739 | HttpRequestInfo unrestricted_port_request; |
| 10740 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10741 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10742 | unrestricted_port_request.load_flags = 0; |
| 10743 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10744 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10745 | StaticSocketDataProvider first_data; |
| 10746 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10747 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10748 | |
| 10749 | MockRead data_reads[] = { |
| 10750 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10751 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10752 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10753 | }; |
| 10754 | StaticSocketDataProvider second_data( |
| 10755 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10756 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10757 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10758 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10759 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10760 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10761 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10762 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10763 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10764 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10765 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10766 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10767 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10768 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10769 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10770 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10771 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10772 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10773 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10774 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10776 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10777 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10778 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10779 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10780 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10781 | } |
| 10782 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10783 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10784 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10785 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10786 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10787 | HttpRequestInfo request; |
| 10788 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10789 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10790 | |
| 10791 | // The alternate protocol request will error out before we attempt to connect, |
| 10792 | // so only the standard HTTP request will try to connect. |
| 10793 | MockRead data_reads[] = { |
| 10794 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10795 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10796 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10797 | }; |
| 10798 | StaticSocketDataProvider data( |
| 10799 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10800 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10801 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10802 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10803 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10804 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10805 | session->http_server_properties(); |
| 10806 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10807 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10808 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10809 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10810 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10811 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10814 | TestCompletionCallback callback; |
| 10815 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10816 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10818 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10819 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10820 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10821 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10822 | ASSERT_TRUE(response); |
| 10823 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10824 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10825 | |
| 10826 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10827 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10828 | EXPECT_EQ("hello world", response_data); |
| 10829 | } |
| 10830 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10831 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10832 | HttpRequestInfo request; |
| 10833 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10834 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10835 | |
| 10836 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10837 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10838 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10839 | MockRead("\r\n"), |
| 10840 | MockRead("hello world"), |
| 10841 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10842 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10843 | |
| 10844 | StaticSocketDataProvider first_transaction( |
| 10845 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10846 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10847 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10848 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10849 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10850 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10851 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10852 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10853 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10854 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10855 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10856 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10857 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10858 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10859 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10860 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10861 | }; |
| 10862 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10863 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10864 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10865 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10866 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10867 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10868 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10869 | NULL, 0, NULL, 0); |
| 10870 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10871 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10872 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10873 | &hanging_non_alternate_protocol_socket); |
| 10874 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10875 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10876 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10877 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10878 | auto trans = |
| 10879 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10880 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10881 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10882 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10883 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10884 | |
| 10885 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10886 | ASSERT_TRUE(response); |
| 10887 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10888 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10889 | |
| 10890 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10891 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10892 | EXPECT_EQ("hello world", response_data); |
| 10893 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10894 | trans = |
| 10895 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10896 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10897 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10898 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10899 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10900 | |
| 10901 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10902 | ASSERT_TRUE(response); |
| 10903 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10904 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10905 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10906 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10907 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10908 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10909 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10910 | } |
| 10911 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10912 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10913 | HttpRequestInfo request; |
| 10914 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10915 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10916 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10917 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10918 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10919 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10920 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10921 | MockRead("\r\n"), |
| 10922 | MockRead("hello world"), |
| 10923 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10924 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10925 | }; |
| 10926 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10927 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 10928 | 0); |
| 10929 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10930 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10931 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
| 10932 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 10933 | |
| 10934 | // Second transaction starts an alternative and a non-alternative Job. |
| 10935 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10936 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10937 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10938 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10939 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10940 | |
| 10941 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10942 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10943 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10944 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10945 | // Third transaction starts an alternative and a non-alternative job. |
| 10946 | // The non-alternative job hangs, but the alternative one succeeds. |
| 10947 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10948 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10949 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10950 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10951 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10952 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10953 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10954 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10955 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10956 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10957 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10958 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10959 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10960 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 10961 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10962 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10963 | }; |
| 10964 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10965 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10966 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10967 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10968 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10969 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10970 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10971 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10972 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10973 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10974 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10975 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10976 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10977 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10978 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10979 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10980 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10981 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10982 | |
| 10983 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10984 | ASSERT_TRUE(response); |
| 10985 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10986 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10987 | |
| 10988 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10989 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10990 | EXPECT_EQ("hello world", response_data); |
| 10991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10992 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10993 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10994 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10995 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10997 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10998 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10999 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11000 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11001 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11002 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11003 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11004 | |
| 11005 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11006 | ASSERT_TRUE(response); |
| 11007 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11008 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11009 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11010 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11011 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11012 | EXPECT_EQ("hello!", response_data); |
| 11013 | |
| 11014 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11015 | ASSERT_TRUE(response); |
| 11016 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11017 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11018 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11019 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11020 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11021 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11022 | } |
| 11023 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11024 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11025 | HttpRequestInfo request; |
| 11026 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11027 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11028 | |
| 11029 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11030 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11031 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11032 | MockRead("\r\n"), |
| 11033 | MockRead("hello world"), |
| 11034 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11035 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11036 | }; |
| 11037 | |
| 11038 | StaticSocketDataProvider first_transaction( |
| 11039 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11040 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11041 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11042 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11043 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11044 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11045 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11046 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11047 | NULL, 0, NULL, 0); |
| 11048 | hanging_alternate_protocol_socket.set_connect_data( |
| 11049 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11050 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11051 | &hanging_alternate_protocol_socket); |
| 11052 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11053 | // 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] | 11054 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11055 | NULL, 0); |
| 11056 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11057 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11058 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11059 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11060 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11061 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11062 | auto trans = |
| 11063 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11064 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11065 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11066 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11067 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11068 | |
| 11069 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11070 | ASSERT_TRUE(response); |
| 11071 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11072 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11073 | |
| 11074 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11075 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11076 | EXPECT_EQ("hello world", response_data); |
| 11077 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11078 | trans = |
| 11079 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11080 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11081 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11082 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11083 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11084 | |
| 11085 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11086 | ASSERT_TRUE(response); |
| 11087 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11088 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11089 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11090 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11091 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11092 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11093 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11094 | } |
| 11095 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11096 | class CapturingProxyResolver : public ProxyResolver { |
| 11097 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11098 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11099 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11100 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11101 | int GetProxyForURL(const GURL& url, |
| 11102 | ProxyInfo* results, |
| 11103 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11104 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11105 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11106 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11107 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11108 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11109 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11110 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11111 | } |
| 11112 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11113 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11114 | |
| 11115 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11116 | std::vector<GURL> resolved_; |
| 11117 | |
| 11118 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11119 | }; |
| 11120 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11121 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11122 | public: |
| 11123 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11124 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11125 | |
| 11126 | int CreateProxyResolver( |
| 11127 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11128 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11129 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11130 | std::unique_ptr<Request>* request) override { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11131 | *resolver = base::MakeUnique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11132 | return OK; |
| 11133 | } |
| 11134 | |
| 11135 | private: |
| 11136 | ProxyResolver* resolver_; |
| 11137 | }; |
| 11138 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11139 | // Test that proxy is resolved using the origin url, |
| 11140 | // regardless of the alternative server. |
| 11141 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11142 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11143 | ProxyConfig proxy_config; |
| 11144 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11145 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11146 | auto proxy_config_service = |
| 11147 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config); |
| 11148 | |
| 11149 | CapturingProxyResolver capturing_proxy_resolver; |
| 11150 | auto proxy_resolver_factory = base::MakeUnique<CapturingProxyResolverFactory>( |
| 11151 | &capturing_proxy_resolver); |
| 11152 | |
| 11153 | TestNetLog net_log; |
| 11154 | |
| 11155 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11156 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11157 | &net_log); |
| 11158 | |
| 11159 | session_deps_.net_log = &net_log; |
| 11160 | |
| 11161 | // Configure alternative service with a hostname that is not bypassed by the |
| 11162 | // proxy. |
| 11163 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11164 | HttpServerProperties* http_server_properties = |
| 11165 | session->http_server_properties(); |
| 11166 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11167 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11168 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11169 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11170 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 11171 | expiration); |
| 11172 | |
| 11173 | // Non-alternative job should hang. |
| 11174 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11175 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11176 | nullptr, 0); |
| 11177 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11178 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11179 | &hanging_alternate_protocol_socket); |
| 11180 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11181 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11182 | |
| 11183 | HttpRequestInfo request; |
| 11184 | request.method = "GET"; |
| 11185 | request.url = GURL("https://www.example.org/"); |
| 11186 | request.load_flags = 0; |
| 11187 | |
| 11188 | SpdySerializedFrame req( |
| 11189 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11190 | |
| 11191 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11192 | |
| 11193 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11194 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11195 | MockRead spdy_reads[] = { |
| 11196 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11197 | }; |
| 11198 | |
| 11199 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11200 | arraysize(spdy_writes)); |
| 11201 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11202 | |
| 11203 | TestCompletionCallback callback; |
| 11204 | |
| 11205 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11206 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11207 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11208 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11209 | |
| 11210 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11211 | ASSERT_TRUE(response); |
| 11212 | ASSERT_TRUE(response->headers); |
| 11213 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11214 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11215 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11216 | |
| 11217 | std::string response_data; |
| 11218 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11219 | EXPECT_EQ("hello!", response_data); |
| 11220 | |
| 11221 | // Origin host bypasses proxy, no resolution should have happened. |
| 11222 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11223 | } |
| 11224 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11225 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11226 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11227 | proxy_config.set_auto_detect(true); |
| 11228 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11229 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11230 | CapturingProxyResolver capturing_proxy_resolver; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11231 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11232 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 11233 | base::MakeUnique<CapturingProxyResolverFactory>( |
| 11234 | &capturing_proxy_resolver), |
| 11235 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11236 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11237 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11238 | |
| 11239 | HttpRequestInfo request; |
| 11240 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11241 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11242 | |
| 11243 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11244 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11245 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11246 | MockRead("\r\n"), |
| 11247 | MockRead("hello world"), |
| 11248 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11249 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11250 | }; |
| 11251 | |
| 11252 | StaticSocketDataProvider first_transaction( |
| 11253 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11254 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11255 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11256 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11257 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11258 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11259 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11260 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11261 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11262 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11263 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11264 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11265 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11266 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11267 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11268 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11269 | }; |
| 11270 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11271 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11272 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11273 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11274 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11275 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11276 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11277 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11278 | }; |
| 11279 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11280 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11281 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11282 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11283 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11284 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11285 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11286 | NULL, 0, NULL, 0); |
| 11287 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11288 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11289 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11290 | &hanging_non_alternate_protocol_socket); |
| 11291 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11292 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11293 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11294 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11295 | auto trans = |
| 11296 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11297 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11298 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11299 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11300 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11301 | |
| 11302 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11303 | ASSERT_TRUE(response); |
| 11304 | ASSERT_TRUE(response->headers); |
| 11305 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 11306 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11307 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11308 | |
| 11309 | std::string response_data; |
| 11310 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 11311 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11312 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11313 | trans = |
| 11314 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11315 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11316 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11317 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11318 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11319 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11320 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11321 | ASSERT_TRUE(response); |
| 11322 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11323 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11324 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11325 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11326 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11327 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11328 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11329 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11330 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11331 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11332 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11333 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11334 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11335 | LoadTimingInfo load_timing_info; |
| 11336 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11337 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11338 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11339 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11340 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11341 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11342 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11343 | HttpRequestInfo request; |
| 11344 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11345 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11346 | |
| 11347 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11348 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11349 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11350 | MockRead("\r\n"), |
| 11351 | MockRead("hello world"), |
| 11352 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11353 | }; |
| 11354 | |
| 11355 | StaticSocketDataProvider first_transaction( |
| 11356 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11357 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11358 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11359 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11360 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11361 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11362 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11363 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11364 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11365 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11366 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11367 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11368 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11369 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11370 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11371 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11372 | }; |
| 11373 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11374 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11375 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11376 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11377 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11378 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11379 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11380 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11381 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11382 | auto trans = |
| 11383 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11384 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11385 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11386 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11387 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11388 | |
| 11389 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11390 | ASSERT_TRUE(response); |
| 11391 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11392 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11393 | |
| 11394 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11395 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11396 | EXPECT_EQ("hello world", response_data); |
| 11397 | |
| 11398 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11399 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11400 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11401 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11402 | base::WeakPtr<SpdySession> spdy_session = |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11403 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11404 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11405 | trans = |
| 11406 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11407 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11408 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11409 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11410 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11411 | |
| 11412 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11413 | ASSERT_TRUE(response); |
| 11414 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11415 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11416 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11417 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11418 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11419 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11420 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11421 | } |
| 11422 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11423 | // GenerateAuthToken is a mighty big test. |
| 11424 | // It tests all permutation of GenerateAuthToken behavior: |
| 11425 | // - Synchronous and Asynchronous completion. |
| 11426 | // - OK or error on completion. |
| 11427 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11428 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11429 | // - Non-authenticating and authenticating backend. |
| 11430 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11431 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11432 | // problems generating an auth token for an authenticating proxy, we don't |
| 11433 | // need to test all permutations of the backend server). |
| 11434 | // |
| 11435 | // The test proceeds by going over each of the configuration cases, and |
| 11436 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11437 | // specifies both the configuration for the test as well as the expectations |
| 11438 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11439 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11440 | static const char kServer[] = "http://www.example.com"; |
| 11441 | static const char kSecureServer[] = "https://www.example.com"; |
| 11442 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11443 | |
| 11444 | enum AuthTiming { |
| 11445 | AUTH_NONE, |
| 11446 | AUTH_SYNC, |
| 11447 | AUTH_ASYNC, |
| 11448 | }; |
| 11449 | |
| 11450 | const MockWrite kGet( |
| 11451 | "GET / HTTP/1.1\r\n" |
| 11452 | "Host: www.example.com\r\n" |
| 11453 | "Connection: keep-alive\r\n\r\n"); |
| 11454 | const MockWrite kGetProxy( |
| 11455 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11456 | "Host: www.example.com\r\n" |
| 11457 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11458 | const MockWrite kGetAuth( |
| 11459 | "GET / HTTP/1.1\r\n" |
| 11460 | "Host: www.example.com\r\n" |
| 11461 | "Connection: keep-alive\r\n" |
| 11462 | "Authorization: auth_token\r\n\r\n"); |
| 11463 | const MockWrite kGetProxyAuth( |
| 11464 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11465 | "Host: www.example.com\r\n" |
| 11466 | "Proxy-Connection: keep-alive\r\n" |
| 11467 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11468 | const MockWrite kGetAuthThroughProxy( |
| 11469 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11470 | "Host: www.example.com\r\n" |
| 11471 | "Proxy-Connection: keep-alive\r\n" |
| 11472 | "Authorization: auth_token\r\n\r\n"); |
| 11473 | const MockWrite kGetAuthWithProxyAuth( |
| 11474 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11475 | "Host: www.example.com\r\n" |
| 11476 | "Proxy-Connection: keep-alive\r\n" |
| 11477 | "Proxy-Authorization: auth_token\r\n" |
| 11478 | "Authorization: auth_token\r\n\r\n"); |
| 11479 | const MockWrite kConnect( |
| 11480 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11481 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11482 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11483 | const MockWrite kConnectProxyAuth( |
| 11484 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11485 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11486 | "Proxy-Connection: keep-alive\r\n" |
| 11487 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11488 | |
| 11489 | const MockRead kSuccess( |
| 11490 | "HTTP/1.1 200 OK\r\n" |
| 11491 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11492 | "Content-Length: 3\r\n\r\n" |
| 11493 | "Yes"); |
| 11494 | const MockRead kFailure( |
| 11495 | "Should not be called."); |
| 11496 | const MockRead kServerChallenge( |
| 11497 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11498 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11499 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11500 | "Content-Length: 14\r\n\r\n" |
| 11501 | "Unauthorized\r\n"); |
| 11502 | const MockRead kProxyChallenge( |
| 11503 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11504 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11505 | "Proxy-Connection: close\r\n" |
| 11506 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11507 | "Content-Length: 14\r\n\r\n" |
| 11508 | "Unauthorized\r\n"); |
| 11509 | const MockRead kProxyConnected( |
| 11510 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11511 | |
| 11512 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11513 | // no constructors, but the C++ compiler on Windows warns about |
| 11514 | // unspecified data in compound literals. So, moved to using constructors, |
| 11515 | // and TestRound's created with the default constructor should not be used. |
| 11516 | struct TestRound { |
| 11517 | TestRound() |
| 11518 | : expected_rv(ERR_UNEXPECTED), |
| 11519 | extra_write(NULL), |
| 11520 | extra_read(NULL) { |
| 11521 | } |
| 11522 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11523 | int expected_rv_arg) |
| 11524 | : write(write_arg), |
| 11525 | read(read_arg), |
| 11526 | expected_rv(expected_rv_arg), |
| 11527 | extra_write(NULL), |
| 11528 | extra_read(NULL) { |
| 11529 | } |
| 11530 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11531 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11532 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11533 | : write(write_arg), |
| 11534 | read(read_arg), |
| 11535 | expected_rv(expected_rv_arg), |
| 11536 | extra_write(extra_write_arg), |
| 11537 | extra_read(extra_read_arg) { |
| 11538 | } |
| 11539 | MockWrite write; |
| 11540 | MockRead read; |
| 11541 | int expected_rv; |
| 11542 | const MockWrite* extra_write; |
| 11543 | const MockRead* extra_read; |
| 11544 | }; |
| 11545 | |
| 11546 | static const int kNoSSL = 500; |
| 11547 | |
| 11548 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11549 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11550 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11551 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11552 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11553 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11554 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11555 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11556 | int num_auth_rounds; |
| 11557 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11558 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11559 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11560 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11561 | {__LINE__, |
| 11562 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11563 | AUTH_NONE, |
| 11564 | OK, |
| 11565 | kServer, |
| 11566 | AUTH_NONE, |
| 11567 | OK, |
| 11568 | 1, |
| 11569 | kNoSSL, |
| 11570 | {TestRound(kGet, kSuccess, OK)}}, |
| 11571 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11572 | {__LINE__, |
| 11573 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11574 | AUTH_NONE, |
| 11575 | OK, |
| 11576 | kServer, |
| 11577 | AUTH_SYNC, |
| 11578 | OK, |
| 11579 | 2, |
| 11580 | kNoSSL, |
| 11581 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11582 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11583 | {__LINE__, |
| 11584 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11585 | AUTH_NONE, |
| 11586 | OK, |
| 11587 | kServer, |
| 11588 | AUTH_SYNC, |
| 11589 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11590 | 3, |
| 11591 | kNoSSL, |
| 11592 | {TestRound(kGet, kServerChallenge, OK), |
| 11593 | TestRound(kGet, kServerChallenge, OK), |
| 11594 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11595 | {__LINE__, |
| 11596 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11597 | AUTH_NONE, |
| 11598 | OK, |
| 11599 | kServer, |
| 11600 | AUTH_SYNC, |
| 11601 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11602 | 2, |
| 11603 | kNoSSL, |
| 11604 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11605 | {__LINE__, |
| 11606 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11607 | AUTH_NONE, |
| 11608 | OK, |
| 11609 | kServer, |
| 11610 | AUTH_SYNC, |
| 11611 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 11612 | 2, |
| 11613 | kNoSSL, |
| 11614 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11615 | {__LINE__, |
| 11616 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11617 | AUTH_SYNC, |
| 11618 | ERR_FAILED, |
| 11619 | kServer, |
| 11620 | AUTH_NONE, |
| 11621 | OK, |
| 11622 | 2, |
| 11623 | kNoSSL, |
| 11624 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11625 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11626 | {__LINE__, |
| 11627 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11628 | AUTH_ASYNC, |
| 11629 | ERR_FAILED, |
| 11630 | kServer, |
| 11631 | AUTH_NONE, |
| 11632 | OK, |
| 11633 | 2, |
| 11634 | kNoSSL, |
| 11635 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11636 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11637 | {__LINE__, |
| 11638 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11639 | AUTH_NONE, |
| 11640 | OK, |
| 11641 | kServer, |
| 11642 | AUTH_SYNC, |
| 11643 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11644 | 2, |
| 11645 | kNoSSL, |
| 11646 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11647 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11648 | {__LINE__, |
| 11649 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11650 | AUTH_NONE, |
| 11651 | OK, |
| 11652 | kServer, |
| 11653 | AUTH_ASYNC, |
| 11654 | ERR_FAILED, |
| 11655 | 2, |
| 11656 | kNoSSL, |
| 11657 | {TestRound(kGet, kServerChallenge, OK), |
| 11658 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11659 | {__LINE__, |
| 11660 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11661 | AUTH_NONE, |
| 11662 | OK, |
| 11663 | kServer, |
| 11664 | AUTH_ASYNC, |
| 11665 | OK, |
| 11666 | 2, |
| 11667 | kNoSSL, |
| 11668 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11669 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11670 | {__LINE__, |
| 11671 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11672 | AUTH_NONE, |
| 11673 | OK, |
| 11674 | kServer, |
| 11675 | AUTH_ASYNC, |
| 11676 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11677 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11678 | kNoSSL, |
| 11679 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11680 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 11681 | TestRound(kGet, kServerChallenge, OK), |
| 11682 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11683 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11684 | {__LINE__, |
| 11685 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11686 | AUTH_NONE, |
| 11687 | OK, |
| 11688 | kServer, |
| 11689 | AUTH_NONE, |
| 11690 | OK, |
| 11691 | 1, |
| 11692 | kNoSSL, |
| 11693 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 11694 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11695 | {__LINE__, |
| 11696 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11697 | AUTH_NONE, |
| 11698 | OK, |
| 11699 | kServer, |
| 11700 | AUTH_SYNC, |
| 11701 | OK, |
| 11702 | 2, |
| 11703 | kNoSSL, |
| 11704 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11705 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11706 | {__LINE__, |
| 11707 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11708 | AUTH_NONE, |
| 11709 | OK, |
| 11710 | kServer, |
| 11711 | AUTH_SYNC, |
| 11712 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11713 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11714 | kNoSSL, |
| 11715 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11716 | TestRound(kGetProxy, kServerChallenge, OK), |
| 11717 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11718 | {__LINE__, |
| 11719 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11720 | AUTH_NONE, |
| 11721 | OK, |
| 11722 | kServer, |
| 11723 | AUTH_ASYNC, |
| 11724 | OK, |
| 11725 | 2, |
| 11726 | kNoSSL, |
| 11727 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11728 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11729 | {__LINE__, |
| 11730 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11731 | AUTH_NONE, |
| 11732 | OK, |
| 11733 | kServer, |
| 11734 | AUTH_ASYNC, |
| 11735 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11736 | 2, |
| 11737 | kNoSSL, |
| 11738 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11739 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11740 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11741 | {__LINE__, |
| 11742 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11743 | AUTH_SYNC, |
| 11744 | OK, |
| 11745 | kServer, |
| 11746 | AUTH_NONE, |
| 11747 | OK, |
| 11748 | 2, |
| 11749 | kNoSSL, |
| 11750 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11751 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11752 | {__LINE__, |
| 11753 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11754 | AUTH_SYNC, |
| 11755 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11756 | kServer, |
| 11757 | AUTH_NONE, |
| 11758 | OK, |
| 11759 | 2, |
| 11760 | kNoSSL, |
| 11761 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11762 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11763 | {__LINE__, |
| 11764 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11765 | AUTH_ASYNC, |
| 11766 | OK, |
| 11767 | kServer, |
| 11768 | AUTH_NONE, |
| 11769 | OK, |
| 11770 | 2, |
| 11771 | kNoSSL, |
| 11772 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11773 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11774 | {__LINE__, |
| 11775 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11776 | AUTH_ASYNC, |
| 11777 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11778 | kServer, |
| 11779 | AUTH_NONE, |
| 11780 | OK, |
| 11781 | 2, |
| 11782 | kNoSSL, |
| 11783 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11784 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11785 | {__LINE__, |
| 11786 | kProxy, |
| 11787 | AUTH_ASYNC, |
| 11788 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11789 | kServer, |
| 11790 | AUTH_NONE, |
| 11791 | OK, |
| 11792 | 3, |
| 11793 | kNoSSL, |
| 11794 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11795 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11796 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11797 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11798 | {__LINE__, |
| 11799 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11800 | AUTH_SYNC, |
| 11801 | OK, |
| 11802 | kServer, |
| 11803 | AUTH_SYNC, |
| 11804 | OK, |
| 11805 | 3, |
| 11806 | kNoSSL, |
| 11807 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11808 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11809 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11810 | {__LINE__, |
| 11811 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11812 | AUTH_SYNC, |
| 11813 | OK, |
| 11814 | kServer, |
| 11815 | AUTH_SYNC, |
| 11816 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11817 | 3, |
| 11818 | kNoSSL, |
| 11819 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11820 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11821 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11822 | {__LINE__, |
| 11823 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11824 | AUTH_ASYNC, |
| 11825 | OK, |
| 11826 | kServer, |
| 11827 | AUTH_SYNC, |
| 11828 | OK, |
| 11829 | 3, |
| 11830 | kNoSSL, |
| 11831 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11832 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11833 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11834 | {__LINE__, |
| 11835 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11836 | AUTH_ASYNC, |
| 11837 | OK, |
| 11838 | kServer, |
| 11839 | AUTH_SYNC, |
| 11840 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11841 | 3, |
| 11842 | kNoSSL, |
| 11843 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11844 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11845 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11846 | {__LINE__, |
| 11847 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11848 | AUTH_SYNC, |
| 11849 | OK, |
| 11850 | kServer, |
| 11851 | AUTH_ASYNC, |
| 11852 | OK, |
| 11853 | 3, |
| 11854 | kNoSSL, |
| 11855 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11856 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11857 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11858 | {__LINE__, |
| 11859 | kProxy, |
| 11860 | AUTH_SYNC, |
| 11861 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11862 | kServer, |
| 11863 | AUTH_ASYNC, |
| 11864 | OK, |
| 11865 | 4, |
| 11866 | kNoSSL, |
| 11867 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11868 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11869 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11870 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11871 | {__LINE__, |
| 11872 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11873 | AUTH_SYNC, |
| 11874 | OK, |
| 11875 | kServer, |
| 11876 | AUTH_ASYNC, |
| 11877 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11878 | 3, |
| 11879 | kNoSSL, |
| 11880 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11881 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11882 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11883 | {__LINE__, |
| 11884 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11885 | AUTH_ASYNC, |
| 11886 | OK, |
| 11887 | kServer, |
| 11888 | AUTH_ASYNC, |
| 11889 | OK, |
| 11890 | 3, |
| 11891 | kNoSSL, |
| 11892 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11893 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11894 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11895 | {__LINE__, |
| 11896 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11897 | AUTH_ASYNC, |
| 11898 | OK, |
| 11899 | kServer, |
| 11900 | AUTH_ASYNC, |
| 11901 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11902 | 3, |
| 11903 | kNoSSL, |
| 11904 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11905 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11906 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11907 | {__LINE__, |
| 11908 | kProxy, |
| 11909 | AUTH_ASYNC, |
| 11910 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11911 | kServer, |
| 11912 | AUTH_ASYNC, |
| 11913 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11914 | 4, |
| 11915 | kNoSSL, |
| 11916 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11917 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11918 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11919 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11920 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11921 | {__LINE__, |
| 11922 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11923 | AUTH_NONE, |
| 11924 | OK, |
| 11925 | kSecureServer, |
| 11926 | AUTH_NONE, |
| 11927 | OK, |
| 11928 | 1, |
| 11929 | 0, |
| 11930 | {TestRound(kGet, kSuccess, OK)}}, |
| 11931 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11932 | {__LINE__, |
| 11933 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11934 | AUTH_NONE, |
| 11935 | OK, |
| 11936 | kSecureServer, |
| 11937 | AUTH_SYNC, |
| 11938 | OK, |
| 11939 | 2, |
| 11940 | 0, |
| 11941 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11942 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11943 | {__LINE__, |
| 11944 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11945 | AUTH_NONE, |
| 11946 | OK, |
| 11947 | kSecureServer, |
| 11948 | AUTH_SYNC, |
| 11949 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11950 | 2, |
| 11951 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11952 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11953 | {__LINE__, |
| 11954 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11955 | AUTH_NONE, |
| 11956 | OK, |
| 11957 | kSecureServer, |
| 11958 | AUTH_ASYNC, |
| 11959 | OK, |
| 11960 | 2, |
| 11961 | 0, |
| 11962 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11963 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11964 | {__LINE__, |
| 11965 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11966 | AUTH_NONE, |
| 11967 | OK, |
| 11968 | kSecureServer, |
| 11969 | AUTH_ASYNC, |
| 11970 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11971 | 2, |
| 11972 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11973 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11974 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11975 | {__LINE__, |
| 11976 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11977 | AUTH_NONE, |
| 11978 | OK, |
| 11979 | kSecureServer, |
| 11980 | AUTH_NONE, |
| 11981 | OK, |
| 11982 | 1, |
| 11983 | 0, |
| 11984 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11985 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11986 | {__LINE__, |
| 11987 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11988 | AUTH_NONE, |
| 11989 | OK, |
| 11990 | kSecureServer, |
| 11991 | AUTH_SYNC, |
| 11992 | OK, |
| 11993 | 2, |
| 11994 | 0, |
| 11995 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11996 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11997 | {__LINE__, |
| 11998 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11999 | AUTH_NONE, |
| 12000 | OK, |
| 12001 | kSecureServer, |
| 12002 | AUTH_SYNC, |
| 12003 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12004 | 2, |
| 12005 | 0, |
| 12006 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12007 | TestRound(kGet, kSuccess, OK)}}, |
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 | kSecureServer, |
| 12013 | AUTH_ASYNC, |
| 12014 | OK, |
| 12015 | 2, |
| 12016 | 0, |
| 12017 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12018 | TestRound(kGetAuth, kSuccess, OK)}}, |
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 | kSecureServer, |
| 12024 | AUTH_ASYNC, |
| 12025 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12026 | 2, |
| 12027 | 0, |
| 12028 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12029 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12030 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12031 | {__LINE__, |
| 12032 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12033 | AUTH_SYNC, |
| 12034 | OK, |
| 12035 | kSecureServer, |
| 12036 | AUTH_NONE, |
| 12037 | OK, |
| 12038 | 2, |
| 12039 | 1, |
| 12040 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12041 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
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_SYNC, |
| 12045 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12046 | kSecureServer, |
| 12047 | AUTH_NONE, |
| 12048 | OK, |
| 12049 | 2, |
| 12050 | kNoSSL, |
| 12051 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12052 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12053 | {__LINE__, |
| 12054 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12055 | AUTH_SYNC, |
| 12056 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12057 | kSecureServer, |
| 12058 | AUTH_NONE, |
| 12059 | OK, |
| 12060 | 2, |
| 12061 | kNoSSL, |
| 12062 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12063 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12064 | {__LINE__, |
| 12065 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12066 | AUTH_SYNC, |
| 12067 | ERR_UNEXPECTED, |
| 12068 | kSecureServer, |
| 12069 | AUTH_NONE, |
| 12070 | OK, |
| 12071 | 2, |
| 12072 | kNoSSL, |
| 12073 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12074 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12075 | {__LINE__, |
| 12076 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12077 | AUTH_ASYNC, |
| 12078 | OK, |
| 12079 | kSecureServer, |
| 12080 | AUTH_NONE, |
| 12081 | OK, |
| 12082 | 2, |
| 12083 | 1, |
| 12084 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12085 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12086 | {__LINE__, |
| 12087 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12088 | AUTH_ASYNC, |
| 12089 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12090 | kSecureServer, |
| 12091 | AUTH_NONE, |
| 12092 | OK, |
| 12093 | 2, |
| 12094 | kNoSSL, |
| 12095 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12096 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12097 | // Authenticating HTTPS server through an authenticating proxy. |
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_SYNC, |
| 12101 | OK, |
| 12102 | kSecureServer, |
| 12103 | AUTH_SYNC, |
| 12104 | OK, |
| 12105 | 3, |
| 12106 | 1, |
| 12107 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12108 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12109 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12110 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12111 | {__LINE__, |
| 12112 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12113 | AUTH_SYNC, |
| 12114 | OK, |
| 12115 | kSecureServer, |
| 12116 | AUTH_SYNC, |
| 12117 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12118 | 3, |
| 12119 | 1, |
| 12120 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12121 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12122 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12123 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12124 | {__LINE__, |
| 12125 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12126 | AUTH_ASYNC, |
| 12127 | OK, |
| 12128 | kSecureServer, |
| 12129 | AUTH_SYNC, |
| 12130 | OK, |
| 12131 | 3, |
| 12132 | 1, |
| 12133 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12134 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12135 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12136 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12137 | {__LINE__, |
| 12138 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12139 | AUTH_ASYNC, |
| 12140 | OK, |
| 12141 | kSecureServer, |
| 12142 | AUTH_SYNC, |
| 12143 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12144 | 3, |
| 12145 | 1, |
| 12146 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12147 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12148 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12149 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12150 | {__LINE__, |
| 12151 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12152 | AUTH_SYNC, |
| 12153 | OK, |
| 12154 | kSecureServer, |
| 12155 | AUTH_ASYNC, |
| 12156 | OK, |
| 12157 | 3, |
| 12158 | 1, |
| 12159 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12160 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12161 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12162 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12163 | {__LINE__, |
| 12164 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12165 | AUTH_SYNC, |
| 12166 | OK, |
| 12167 | kSecureServer, |
| 12168 | AUTH_ASYNC, |
| 12169 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12170 | 3, |
| 12171 | 1, |
| 12172 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12173 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12174 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12175 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12176 | {__LINE__, |
| 12177 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12178 | AUTH_ASYNC, |
| 12179 | OK, |
| 12180 | kSecureServer, |
| 12181 | AUTH_ASYNC, |
| 12182 | OK, |
| 12183 | 3, |
| 12184 | 1, |
| 12185 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12186 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12187 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12188 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12189 | {__LINE__, |
| 12190 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12191 | AUTH_ASYNC, |
| 12192 | OK, |
| 12193 | kSecureServer, |
| 12194 | AUTH_ASYNC, |
| 12195 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12196 | 3, |
| 12197 | 1, |
| 12198 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12199 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12200 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12201 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12202 | {__LINE__, |
| 12203 | kProxy, |
| 12204 | AUTH_ASYNC, |
| 12205 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12206 | kSecureServer, |
| 12207 | AUTH_ASYNC, |
| 12208 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12209 | 4, |
| 12210 | 2, |
| 12211 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12212 | TestRound(kConnect, kProxyChallenge, OK), |
| 12213 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12214 | &kServerChallenge), |
| 12215 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12216 | }; |
| 12217 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12218 | for (const auto& test_config : test_configs) { |
| 12219 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12220 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12221 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12222 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12223 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12224 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12225 | |
| 12226 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12227 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12228 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12229 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12230 | std::string auth_challenge = "Mock realm=proxy"; |
| 12231 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12232 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12233 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12234 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12235 | empty_ssl_info, origin, |
| 12236 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12237 | auth_handler->SetGenerateExpectation( |
| 12238 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12239 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12240 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12241 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12242 | } |
| 12243 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12244 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12245 | std::string auth_challenge = "Mock realm=server"; |
| 12246 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12247 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12248 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12249 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12250 | empty_ssl_info, origin, |
| 12251 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12252 | auth_handler->SetGenerateExpectation( |
| 12253 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12254 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12255 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12256 | |
| 12257 | // The second handler always succeeds. It should only be used where there |
| 12258 | // are multiple auth sessions for server auth in the same network |
| 12259 | // transaction using the same auth scheme. |
| 12260 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
| 12261 | base::MakeUnique<HttpAuthHandlerMock>(); |
| 12262 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12263 | empty_ssl_info, origin, |
| 12264 | NetLogWithSource()); |
| 12265 | second_handler->SetGenerateExpectation(true, OK); |
| 12266 | auth_factory->AddMockHandler(second_handler.release(), |
| 12267 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12268 | } |
| 12269 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12270 | session_deps_.proxy_service = |
| 12271 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12272 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12273 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12274 | } |
| 12275 | |
| 12276 | HttpRequestInfo request; |
| 12277 | request.method = "GET"; |
| 12278 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12279 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12280 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12281 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12282 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12283 | |
| 12284 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12285 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12286 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12287 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12288 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12289 | |
| 12290 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12291 | mock_reads.back().push_back(read_write_round.read); |
| 12292 | mock_writes.back().push_back(read_write_round.write); |
| 12293 | |
| 12294 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 12295 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12296 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12297 | mock_reads.push_back(std::vector<MockRead>()); |
| 12298 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12299 | } |
| 12300 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12301 | if (read_write_round.extra_read) { |
| 12302 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12303 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12304 | if (read_write_round.extra_write) { |
| 12305 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 12306 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12307 | |
| 12308 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12309 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12310 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12311 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12312 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12313 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12314 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12315 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12316 | data_providers.push_back(base::MakeUnique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12317 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12318 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12319 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12320 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12321 | } |
| 12322 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12323 | // Transaction must be created after DataProviders, so it's destroyed before |
| 12324 | // they are as well. |
| 12325 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12326 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12327 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12328 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12329 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12330 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12331 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12332 | int rv; |
| 12333 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12334 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12335 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12336 | rv = trans.RestartWithAuth( |
| 12337 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12338 | } |
| 12339 | if (rv == ERR_IO_PENDING) |
| 12340 | rv = callback.WaitForResult(); |
| 12341 | |
| 12342 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12343 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12344 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 12345 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12346 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 12347 | continue; |
| 12348 | } |
| 12349 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12350 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12351 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12352 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12353 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12354 | } |
| 12355 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 12356 | } |
| 12357 | } |
| 12358 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12359 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12360 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12361 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12362 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12363 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12364 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12365 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 12366 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12367 | |
| 12368 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12369 | auth_handler->set_connection_based(true); |
| 12370 | std::string auth_challenge = "Mock realm=server"; |
| 12371 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12372 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12373 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12374 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12375 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12376 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12377 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12378 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12379 | int rv = OK; |
| 12380 | const HttpResponseInfo* response = NULL; |
| 12381 | HttpRequestInfo request; |
| 12382 | request.method = "GET"; |
| 12383 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12384 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12385 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12386 | |
| 12387 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 12388 | // to validate that the TCP socket is not released to the pool between |
| 12389 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12390 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12391 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12392 | 50, // Max sockets for pool |
| 12393 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 12394 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 12395 | NULL, session_deps_.net_log); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12396 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 12397 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12398 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12399 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12400 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12401 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12402 | |
| 12403 | const MockWrite kGet( |
| 12404 | "GET / HTTP/1.1\r\n" |
| 12405 | "Host: www.example.com\r\n" |
| 12406 | "Connection: keep-alive\r\n\r\n"); |
| 12407 | const MockWrite kGetAuth( |
| 12408 | "GET / HTTP/1.1\r\n" |
| 12409 | "Host: www.example.com\r\n" |
| 12410 | "Connection: keep-alive\r\n" |
| 12411 | "Authorization: auth_token\r\n\r\n"); |
| 12412 | |
| 12413 | const MockRead kServerChallenge( |
| 12414 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12415 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12416 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12417 | "Content-Length: 14\r\n\r\n" |
| 12418 | "Unauthorized\r\n"); |
| 12419 | const MockRead kSuccess( |
| 12420 | "HTTP/1.1 200 OK\r\n" |
| 12421 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12422 | "Content-Length: 3\r\n\r\n" |
| 12423 | "Yes"); |
| 12424 | |
| 12425 | MockWrite writes[] = { |
| 12426 | // First round |
| 12427 | kGet, |
| 12428 | // Second round |
| 12429 | kGetAuth, |
| 12430 | // Third round |
| 12431 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12432 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12433 | kGetAuth, |
| 12434 | // Competing request |
| 12435 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12436 | }; |
| 12437 | MockRead reads[] = { |
| 12438 | // First round |
| 12439 | kServerChallenge, |
| 12440 | // Second round |
| 12441 | kServerChallenge, |
| 12442 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12443 | kServerChallenge, |
| 12444 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12445 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12446 | // Competing response |
| 12447 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12448 | }; |
| 12449 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 12450 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12451 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12452 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12453 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12454 | |
| 12455 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12456 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12457 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12458 | if (rv == ERR_IO_PENDING) |
| 12459 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12460 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12461 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12462 | ASSERT_TRUE(response); |
| 12463 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12464 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12465 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12466 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12467 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12468 | // In between rounds, another request comes in for the same domain. |
| 12469 | // It should not be able to grab the TCP socket that trans has already |
| 12470 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12471 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12472 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12473 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 12474 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12476 | // callback_compete.WaitForResult at this point would stall forever, |
| 12477 | // since the HttpNetworkTransaction does not release the request back to |
| 12478 | // the pool until after authentication completes. |
| 12479 | |
| 12480 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12481 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12482 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12483 | if (rv == ERR_IO_PENDING) |
| 12484 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12485 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12486 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12487 | ASSERT_TRUE(response); |
| 12488 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12489 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12490 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12491 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12492 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12493 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12494 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12495 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12496 | if (rv == ERR_IO_PENDING) |
| 12497 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12498 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12499 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12500 | ASSERT_TRUE(response); |
| 12501 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12502 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12503 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12504 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12505 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12506 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12507 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12508 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12509 | if (rv == ERR_IO_PENDING) |
| 12510 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12511 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12512 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12513 | ASSERT_TRUE(response); |
| 12514 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12515 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12516 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12517 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 12518 | // auth handler should transition to a DONE state in concert with the remote |
| 12519 | // server. But that's not something we can test here with a mock handler. |
| 12520 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 12521 | auth_handler->state()); |
| 12522 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12523 | // Read the body since the fourth round was successful. This will also |
| 12524 | // release the socket back to the pool. |
| 12525 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12526 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12527 | if (rv == ERR_IO_PENDING) |
| 12528 | rv = callback.WaitForResult(); |
| 12529 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12530 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12531 | EXPECT_EQ(0, rv); |
| 12532 | // There are still 0 idle sockets, since the trans_compete transaction |
| 12533 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12534 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12535 | |
| 12536 | // The competing request can now finish. Wait for the headers and then |
| 12537 | // read the body. |
| 12538 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12539 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12540 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12541 | if (rv == ERR_IO_PENDING) |
| 12542 | rv = callback.WaitForResult(); |
| 12543 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12544 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12545 | EXPECT_EQ(0, rv); |
| 12546 | |
| 12547 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12548 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12549 | } |
| 12550 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12551 | // This tests the case that a request is issued via http instead of spdy after |
| 12552 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12553 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12554 | HttpRequestInfo request; |
| 12555 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12556 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12557 | |
| 12558 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12559 | MockWrite( |
| 12560 | "GET / HTTP/1.1\r\n" |
| 12561 | "Host: www.example.org\r\n" |
| 12562 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12563 | }; |
| 12564 | |
| 12565 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12566 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12567 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12568 | MockRead("\r\n"), |
| 12569 | MockRead("hello world"), |
| 12570 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12571 | }; |
| 12572 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12573 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12574 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12575 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12576 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12577 | |
| 12578 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12579 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12580 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12582 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12583 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12584 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12585 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12586 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12587 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12588 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12589 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12590 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12591 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12592 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12593 | ASSERT_TRUE(response); |
| 12594 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12595 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12596 | |
| 12597 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12598 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12599 | EXPECT_EQ("hello world", response_data); |
| 12600 | |
| 12601 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12602 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12603 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12604 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12605 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12606 | // immediate server closing of the socket. |
| 12607 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12608 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12609 | HttpRequestInfo request; |
| 12610 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12611 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12612 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12613 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12614 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12615 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12616 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12617 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12618 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12619 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12620 | |
| 12621 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12622 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12623 | }; |
| 12624 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12625 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12626 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12627 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12628 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12629 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12630 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12631 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12632 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12633 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12634 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12635 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12636 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12637 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12638 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12639 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12640 | // it gets it. This is needed since the auth handler may get destroyed |
| 12641 | // before we get a chance to query it. |
| 12642 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12643 | public: |
| 12644 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12645 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12646 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12647 | |
| 12648 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12649 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12650 | const HttpRequestInfo* request, |
| 12651 | const CompletionCallback& callback, |
| 12652 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12653 | *url_ = request->url; |
| 12654 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 12655 | credentials, request, callback, auth_token); |
| 12656 | } |
| 12657 | |
| 12658 | private: |
| 12659 | GURL* url_; |
| 12660 | }; |
| 12661 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12662 | // Test that if we cancel the transaction as the connection is completing, that |
| 12663 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12664 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12665 | // Setup everything about the connection to complete synchronously, so that |
| 12666 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12667 | // for is the callback from the HttpStreamRequest. |
| 12668 | // Then cancel the transaction. |
| 12669 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12670 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12671 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12672 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12673 | MockRead(SYNCHRONOUS, "hello world"), |
| 12674 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12675 | }; |
| 12676 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12677 | HttpRequestInfo request; |
| 12678 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12679 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12680 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12681 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12682 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12683 | auto trans = |
| 12684 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12685 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12686 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12687 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12688 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12689 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12690 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12691 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12692 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12693 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12694 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12695 | trans.reset(); // Cancel the transaction here. |
| 12696 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12697 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12698 | } |
| 12699 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12700 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12701 | // stream is drained properly and added back to the socket pool. The main |
| 12702 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12703 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12704 | // deleted. |
| 12705 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12706 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12707 | MockRead data_reads[] = { |
| 12708 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12709 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12710 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12711 | MockRead(ASYNC, "1"), |
| 12712 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12713 | // HttpNetworkTransaction has been deleted. |
| 12714 | MockRead(ASYNC, "2"), |
| 12715 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12716 | }; |
| 12717 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12718 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12719 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12720 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12721 | |
| 12722 | { |
| 12723 | HttpRequestInfo request; |
| 12724 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12725 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12726 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12727 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12728 | TestCompletionCallback callback; |
| 12729 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12730 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12731 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12732 | callback.WaitForResult(); |
| 12733 | |
| 12734 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12735 | ASSERT_TRUE(response); |
| 12736 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12737 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12738 | |
| 12739 | // The transaction and HttpRequestInfo are deleted. |
| 12740 | } |
| 12741 | |
| 12742 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12743 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12744 | |
| 12745 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12746 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12747 | } |
| 12748 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12749 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12750 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12751 | session_deps_.proxy_service = |
| 12752 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12753 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12754 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12756 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12757 | HttpRequestInfo request; |
| 12758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12759 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12760 | |
| 12761 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12762 | MockWrite( |
| 12763 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12764 | "Host: www.example.org\r\n" |
| 12765 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12766 | }; |
| 12767 | |
| 12768 | MockRead data_reads1[] = { |
| 12769 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12770 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12771 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12772 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12773 | }; |
| 12774 | |
| 12775 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12776 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12777 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12778 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12779 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12780 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12781 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12782 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12783 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12784 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12785 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12786 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12787 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12788 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12789 | |
| 12790 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12791 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12792 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12793 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12794 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12795 | |
| 12796 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12797 | EXPECT_EQ(200, response->headers->response_code()); |
| 12798 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12799 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12800 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12801 | HostPortPair::FromString("myproxy:70")), |
| 12802 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12803 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12804 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12805 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12806 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12807 | |
| 12808 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12809 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12810 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12811 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12812 | } |
| 12813 | |
| 12814 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12815 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12816 | session_deps_.proxy_service = |
| 12817 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12818 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12819 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12820 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12821 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12822 | HttpRequestInfo request; |
| 12823 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12824 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12825 | |
| 12826 | // Since we have proxy, should try to establish tunnel. |
| 12827 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12828 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12829 | "Host: www.example.org:443\r\n" |
| 12830 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12831 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12832 | MockWrite("GET / HTTP/1.1\r\n" |
| 12833 | "Host: www.example.org\r\n" |
| 12834 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12835 | }; |
| 12836 | |
| 12837 | MockRead data_reads1[] = { |
| 12838 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12839 | |
| 12840 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12841 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12842 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12843 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12844 | }; |
| 12845 | |
| 12846 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12847 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12848 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12849 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12850 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12851 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12852 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12853 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12854 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12855 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12856 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12857 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12858 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12859 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12860 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12861 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12862 | |
| 12863 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12864 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12865 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12866 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12867 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12868 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12869 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12870 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12871 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12872 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12873 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12874 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12875 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12876 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12877 | |
| 12878 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12879 | EXPECT_EQ(200, response->headers->response_code()); |
| 12880 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12881 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12882 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12883 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12884 | HostPortPair::FromString("myproxy:70")), |
| 12885 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12886 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12887 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12888 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12889 | |
| 12890 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12891 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12892 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12893 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12894 | } |
| 12895 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12896 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12897 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12898 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12899 | session_deps_.proxy_service = |
| 12900 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12901 | BoundTestNetLog log; |
| 12902 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12903 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12904 | |
| 12905 | HttpRequestInfo request; |
| 12906 | request.method = "GET"; |
| 12907 | request.url = GURL("https://[::1]:443/"); |
| 12908 | |
| 12909 | // Since we have proxy, should try to establish tunnel. |
| 12910 | MockWrite data_writes1[] = { |
| 12911 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12912 | "Host: [::1]:443\r\n" |
| 12913 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12914 | |
| 12915 | MockWrite("GET / HTTP/1.1\r\n" |
| 12916 | "Host: [::1]\r\n" |
| 12917 | "Connection: keep-alive\r\n\r\n"), |
| 12918 | }; |
| 12919 | |
| 12920 | MockRead data_reads1[] = { |
| 12921 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12922 | |
| 12923 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12924 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12925 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12926 | MockRead(SYNCHRONOUS, OK), |
| 12927 | }; |
| 12928 | |
| 12929 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12930 | data_writes1, arraysize(data_writes1)); |
| 12931 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12932 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12933 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12934 | |
| 12935 | TestCompletionCallback callback1; |
| 12936 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12937 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12938 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12939 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12941 | |
| 12942 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12943 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12944 | TestNetLogEntry::List entries; |
| 12945 | log.GetEntries(&entries); |
| 12946 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12947 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12948 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12949 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12950 | entries, pos, |
| 12951 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12952 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12953 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12954 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12955 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12956 | |
| 12957 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12958 | EXPECT_EQ(200, response->headers->response_code()); |
| 12959 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12960 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12961 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12962 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12963 | HostPortPair::FromString("myproxy:70")), |
| 12964 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12965 | |
| 12966 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12967 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12968 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12969 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12970 | } |
| 12971 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12972 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12973 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12974 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12975 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12976 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12977 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12978 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12979 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12980 | HttpRequestInfo request; |
| 12981 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12982 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12983 | |
| 12984 | // Since we have proxy, should try to establish tunnel. |
| 12985 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12986 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12987 | "Host: www.example.org:443\r\n" |
| 12988 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12989 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12990 | MockWrite("GET / HTTP/1.1\r\n" |
| 12991 | "Host: www.example.org\r\n" |
| 12992 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12993 | }; |
| 12994 | |
| 12995 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12996 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12997 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12998 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12999 | }; |
| 13000 | |
| 13001 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13002 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13003 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13004 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13005 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13007 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13008 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13009 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13010 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13011 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13012 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13013 | |
| 13014 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13015 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13016 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13017 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13018 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13019 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13020 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13021 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13022 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13023 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13024 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13025 | } |
| 13026 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13027 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13028 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13029 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13030 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13031 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13032 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13033 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13034 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13035 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13036 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13037 | }; |
| 13038 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13039 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13040 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13041 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13042 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13043 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13044 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13045 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13046 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13047 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13048 | |
| 13049 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13050 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13051 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13052 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13053 | base::WeakPtr<SpdySession> spdy_session = |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13054 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13055 | |
| 13056 | HttpRequestInfo request; |
| 13057 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13058 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13059 | |
| 13060 | // This is the important line that marks this as a preconnect. |
| 13061 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13062 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13063 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13064 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13065 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13066 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13067 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13068 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13069 | } |
| 13070 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13071 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13072 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13073 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13074 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13075 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13076 | request_info.url = GURL("https://www.example.com/"); |
| 13077 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13078 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13079 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13080 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13081 | MockWrite data_writes[] = { |
| 13082 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13083 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13084 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13085 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13086 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13087 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13088 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13089 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13090 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13091 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13092 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13093 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13094 | rv = callback.WaitForResult(); |
| 13095 | ASSERT_EQ(error, rv); |
| 13096 | } |
| 13097 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13098 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13099 | // Just check a grab bag of cert errors. |
| 13100 | static const int kErrors[] = { |
| 13101 | ERR_CERT_COMMON_NAME_INVALID, |
| 13102 | ERR_CERT_AUTHORITY_INVALID, |
| 13103 | ERR_CERT_DATE_INVALID, |
| 13104 | }; |
| 13105 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13106 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13107 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13108 | } |
| 13109 | } |
| 13110 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13111 | // Ensure that a client certificate is removed from the SSL client auth |
| 13112 | // cache when: |
| 13113 | // 1) No proxy is involved. |
| 13114 | // 2) TLS False Start is disabled. |
| 13115 | // 3) The initial TLS handshake requests a client certificate. |
| 13116 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13117 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13118 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13119 | request_info.url = GURL("https://www.example.com/"); |
| 13120 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13121 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13122 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13123 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13124 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13125 | |
| 13126 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13127 | // CertificateRequest is received for the first time, the handshake will |
| 13128 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13129 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13130 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13131 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13132 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13133 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13134 | |
| 13135 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13136 | // False Start is not being used, the result of the SSL handshake will be |
| 13137 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13138 | // matches the result of a server sending a handshake_failure alert, |
| 13139 | // rather than a Finished message, because it requires a client |
| 13140 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13141 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13142 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13143 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13144 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13145 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13146 | |
| 13147 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13148 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13149 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13150 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13151 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13152 | // requiring a client certificate, this fallback handshake should also |
| 13153 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13154 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13155 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13156 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13157 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13158 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13159 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13160 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13161 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13162 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13163 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13164 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13165 | // requiring a client certificate, this fallback handshake should also |
| 13166 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13167 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13168 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13169 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13170 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13171 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13172 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13173 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13174 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13175 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13176 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13177 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13178 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13179 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13180 | |
| 13181 | // Complete the SSL handshake, which should abort due to requiring a |
| 13182 | // client certificate. |
| 13183 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13184 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13185 | |
| 13186 | // Indicate that no certificate should be supplied. From the perspective |
| 13187 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13188 | // certificate, so this is the same as supply a |
| 13189 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13190 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13191 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13192 | |
| 13193 | // Ensure the certificate was added to the client auth cache before |
| 13194 | // allowing the connection to continue restarting. |
| 13195 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13196 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13197 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13198 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13199 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13200 | |
| 13201 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13202 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13203 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13204 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13205 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13206 | |
| 13207 | // Ensure that the client certificate is removed from the cache on a |
| 13208 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13209 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13210 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13211 | } |
| 13212 | |
| 13213 | // Ensure that a client certificate is removed from the SSL client auth |
| 13214 | // cache when: |
| 13215 | // 1) No proxy is involved. |
| 13216 | // 2) TLS False Start is enabled. |
| 13217 | // 3) The initial TLS handshake requests a client certificate. |
| 13218 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13219 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13220 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13221 | request_info.url = GURL("https://www.example.com/"); |
| 13222 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13223 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13224 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13225 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13226 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13227 | |
| 13228 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13229 | // return successfully after reading up to the peer's Certificate message. |
| 13230 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13231 | // enqueue application data to be sent in the same packet as the |
| 13232 | // ChangeCipherSpec and Finished messages. |
| 13233 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13234 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13235 | // Finished messages. If there was an error negotiating with the peer, |
| 13236 | // such as due to the peer requiring a client certificate when none was |
| 13237 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13238 | // called. |
| 13239 | |
| 13240 | // Like the non-False Start case, when a client certificate is requested by |
| 13241 | // the peer, the handshake is aborted during the Connect() call. |
| 13242 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13243 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13244 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13245 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13246 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13247 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13248 | |
| 13249 | // When a client certificate is supplied, Connect() will not be aborted |
| 13250 | // when the peer requests the certificate. Instead, the handshake will |
| 13251 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13252 | // the socket. The handshake messages are not processed until Read() is |
| 13253 | // called, which then detects that the handshake was aborted, due to the |
| 13254 | // peer sending a handshake_failure because it requires a client |
| 13255 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13256 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13257 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13258 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13259 | MockRead data2_reads[] = { |
| 13260 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13261 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13262 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13263 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13264 | |
| 13265 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13266 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13267 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13268 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13269 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13270 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13271 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13272 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13273 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13274 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13275 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13276 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13277 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13278 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13279 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13280 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13281 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13282 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13283 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13284 | ssl_data5.cert_request_info = cert_request.get(); |
| 13285 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13286 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13287 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13288 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13289 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13290 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13291 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13292 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13293 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13294 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13295 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13296 | |
| 13297 | // Complete the SSL handshake, which should abort due to requiring a |
| 13298 | // client certificate. |
| 13299 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13300 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13301 | |
| 13302 | // Indicate that no certificate should be supplied. From the perspective |
| 13303 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13304 | // certificate, so this is the same as supply a |
| 13305 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13306 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13307 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13308 | |
| 13309 | // Ensure the certificate was added to the client auth cache before |
| 13310 | // allowing the connection to continue restarting. |
| 13311 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13312 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13313 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13314 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13315 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13316 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13317 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13318 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13319 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13320 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13321 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13322 | |
| 13323 | // Ensure that the client certificate is removed from the cache on a |
| 13324 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13325 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13326 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13327 | } |
| 13328 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13329 | // Ensure that a client certificate is removed from the SSL client auth |
| 13330 | // cache when: |
| 13331 | // 1) An HTTPS proxy is involved. |
| 13332 | // 3) The HTTPS proxy requests a client certificate. |
| 13333 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 13334 | // proxy. |
| 13335 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 13336 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13337 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13338 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13339 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13340 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13341 | |
| 13342 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13343 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13344 | |
| 13345 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 13346 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 13347 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 13348 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13349 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13350 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13351 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13352 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13353 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13354 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13355 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13356 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13357 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13358 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13359 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13360 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13361 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 13362 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13363 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13364 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13365 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13366 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13367 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13368 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13369 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13370 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13371 | requests[0].url = GURL("https://www.example.com/"); |
| 13372 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13373 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13374 | |
| 13375 | requests[1].url = GURL("http://www.example.com/"); |
| 13376 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13377 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13378 | |
| 13379 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13380 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13381 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13382 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13383 | |
| 13384 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13385 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13386 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13387 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13388 | |
| 13389 | // Complete the SSL handshake, which should abort due to requiring a |
| 13390 | // client certificate. |
| 13391 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13392 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13393 | |
| 13394 | // Indicate that no certificate should be supplied. From the perspective |
| 13395 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13396 | // certificate, so this is the same as supply a |
| 13397 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13398 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13399 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13400 | |
| 13401 | // Ensure the certificate was added to the client auth cache before |
| 13402 | // allowing the connection to continue restarting. |
| 13403 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13404 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13405 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13406 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13407 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13408 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13409 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13410 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13411 | HostPortPair("www.example.com", 443), &client_cert, |
| 13412 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13413 | |
| 13414 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13415 | // then consume ssl_data3, which should also fail. The result code is |
| 13416 | // checked against what ssl_data3 should return. |
| 13417 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13418 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13419 | |
| 13420 | // Now that the new handshake has failed, ensure that the client |
| 13421 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13422 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13423 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13424 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13425 | HostPortPair("www.example.com", 443), &client_cert, |
| 13426 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13427 | } |
| 13428 | } |
| 13429 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13430 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13431 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13432 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13433 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13434 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13435 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13436 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13437 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13438 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13439 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13440 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13441 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13442 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13443 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13444 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13445 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13446 | SpdySerializedFrame host1_resp_body( |
| 13447 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13448 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13449 | SpdySerializedFrame host2_resp_body( |
| 13450 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13451 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13452 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13453 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13454 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13455 | }; |
| 13456 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13457 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13458 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13459 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13460 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13461 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13462 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13463 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13464 | HttpRequestInfo request1; |
| 13465 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13466 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13467 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13468 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13469 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13470 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13471 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13472 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13473 | |
| 13474 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13475 | ASSERT_TRUE(response); |
| 13476 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13477 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13478 | |
| 13479 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13480 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13481 | EXPECT_EQ("hello!", response_data); |
| 13482 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13483 | // Preload mail.example.com into HostCache. |
| 13484 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13485 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13486 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13487 | std::unique_ptr<HostResolver::Request> request; |
| 13488 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13489 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13490 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13491 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13492 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13493 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13494 | |
| 13495 | HttpRequestInfo request2; |
| 13496 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13497 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13498 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13499 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13500 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13501 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13502 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13503 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13504 | |
| 13505 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13506 | ASSERT_TRUE(response); |
| 13507 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13508 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13509 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13510 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13511 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13512 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13513 | } |
| 13514 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13515 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13516 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13517 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13518 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13519 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13520 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13521 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13522 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13523 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13524 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13525 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13526 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13527 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13528 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13529 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13530 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13531 | SpdySerializedFrame host1_resp_body( |
| 13532 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13533 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13534 | SpdySerializedFrame host2_resp_body( |
| 13535 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13536 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13537 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13538 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13539 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13540 | }; |
| 13541 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13542 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13543 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13544 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13545 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13546 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13547 | |
| 13548 | TestCompletionCallback callback; |
| 13549 | HttpRequestInfo request1; |
| 13550 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13551 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13552 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13553 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13554 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13555 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13556 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13557 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13558 | |
| 13559 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13560 | ASSERT_TRUE(response); |
| 13561 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13562 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13563 | |
| 13564 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13565 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13566 | EXPECT_EQ("hello!", response_data); |
| 13567 | |
| 13568 | HttpRequestInfo request2; |
| 13569 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13570 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13571 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13572 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13573 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13574 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13575 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13576 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13577 | |
| 13578 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13579 | ASSERT_TRUE(response); |
| 13580 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13581 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13582 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13583 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13584 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13585 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13586 | } |
| 13587 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13588 | // Regression test for https://crbug.com/546991. |
| 13589 | // The server might not be able to serve an IP pooled request, and might send a |
| 13590 | // 421 Misdirected Request response status to indicate this. |
| 13591 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 13592 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 13593 | // Two hosts resolve to the same IP address. |
| 13594 | const std::string ip_addr = "1.2.3.4"; |
| 13595 | IPAddress ip; |
| 13596 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13597 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13598 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13599 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13600 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13601 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13602 | |
| 13603 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13604 | |
| 13605 | // Two requests on the first connection. |
| 13606 | SpdySerializedFrame req1( |
| 13607 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13608 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13609 | SpdySerializedFrame req2( |
| 13610 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13611 | SpdySerializedFrame rst( |
| 13612 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13613 | MockWrite writes1[] = { |
| 13614 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13615 | CreateMockWrite(rst, 6), |
| 13616 | }; |
| 13617 | |
| 13618 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13619 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13620 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13621 | SpdyHeaderBlock response_headers; |
| 13622 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13623 | SpdySerializedFrame resp2( |
| 13624 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 13625 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13626 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13627 | |
| 13628 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13629 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13630 | arraysize(writes1)); |
| 13631 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13632 | |
| 13633 | AddSSLSocketData(); |
| 13634 | |
| 13635 | // Retry the second request on a second connection. |
| 13636 | SpdyTestUtil spdy_util2; |
| 13637 | SpdySerializedFrame req3( |
| 13638 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13639 | MockWrite writes2[] = { |
| 13640 | CreateMockWrite(req3, 0), |
| 13641 | }; |
| 13642 | |
| 13643 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13644 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13645 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13646 | MockRead(ASYNC, 0, 3)}; |
| 13647 | |
| 13648 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13649 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13650 | arraysize(writes2)); |
| 13651 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13652 | |
| 13653 | AddSSLSocketData(); |
| 13654 | |
| 13655 | // Preload mail.example.org into HostCache. |
| 13656 | HostPortPair host_port("mail.example.org", 443); |
| 13657 | HostResolver::RequestInfo resolve_info(host_port); |
| 13658 | AddressList ignored; |
| 13659 | std::unique_ptr<HostResolver::Request> request; |
| 13660 | TestCompletionCallback callback; |
| 13661 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13662 | &ignored, callback.callback(), |
| 13663 | &request, NetLogWithSource()); |
| 13664 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13665 | rv = callback.WaitForResult(); |
| 13666 | EXPECT_THAT(rv, IsOk()); |
| 13667 | |
| 13668 | HttpRequestInfo request1; |
| 13669 | request1.method = "GET"; |
| 13670 | request1.url = GURL("https://www.example.org/"); |
| 13671 | request1.load_flags = 0; |
| 13672 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13673 | |
| 13674 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 13675 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13676 | rv = callback.WaitForResult(); |
| 13677 | EXPECT_THAT(rv, IsOk()); |
| 13678 | |
| 13679 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13680 | ASSERT_TRUE(response); |
| 13681 | ASSERT_TRUE(response->headers); |
| 13682 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13683 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13684 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13685 | std::string response_data; |
| 13686 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 13687 | EXPECT_EQ("hello!", response_data); |
| 13688 | |
| 13689 | HttpRequestInfo request2; |
| 13690 | request2.method = "GET"; |
| 13691 | request2.url = GURL("https://mail.example.org/"); |
| 13692 | request2.load_flags = 0; |
| 13693 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13694 | |
| 13695 | BoundTestNetLog log; |
| 13696 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 13697 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13698 | rv = callback.WaitForResult(); |
| 13699 | EXPECT_THAT(rv, IsOk()); |
| 13700 | |
| 13701 | response = trans2.GetResponseInfo(); |
| 13702 | ASSERT_TRUE(response); |
| 13703 | ASSERT_TRUE(response->headers); |
| 13704 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13705 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13706 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13707 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 13708 | EXPECT_EQ("hello!", response_data); |
| 13709 | |
| 13710 | TestNetLogEntry::List entries; |
| 13711 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13712 | ExpectLogContainsSomewhere( |
| 13713 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13714 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13715 | } |
| 13716 | |
| 13717 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 13718 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 13719 | // portions of the response. |
| 13720 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 13721 | // Two hosts resolve to the same IP address. |
| 13722 | const std::string ip_addr = "1.2.3.4"; |
| 13723 | IPAddress ip; |
| 13724 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13725 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13726 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13727 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13728 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13729 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13730 | |
| 13731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13732 | |
| 13733 | // Two requests on the first connection. |
| 13734 | SpdySerializedFrame req1( |
| 13735 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13736 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13737 | SpdySerializedFrame req2( |
| 13738 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13739 | SpdySerializedFrame rst( |
| 13740 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13741 | MockWrite writes1[] = { |
| 13742 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13743 | CreateMockWrite(rst, 6), |
| 13744 | }; |
| 13745 | |
| 13746 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13747 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13748 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13749 | SpdyHeaderBlock response_headers; |
| 13750 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13751 | SpdySerializedFrame resp2( |
| 13752 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 13753 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13754 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13755 | |
| 13756 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13757 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13758 | arraysize(writes1)); |
| 13759 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13760 | |
| 13761 | AddSSLSocketData(); |
| 13762 | |
| 13763 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 13764 | // Retry again. |
| 13765 | SpdyTestUtil spdy_util2; |
| 13766 | SpdySerializedFrame req3( |
| 13767 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13768 | MockWrite writes2[] = { |
| 13769 | CreateMockWrite(req3, 0), |
| 13770 | }; |
| 13771 | |
| 13772 | SpdySerializedFrame resp3( |
| 13773 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 13774 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13775 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13776 | MockRead(ASYNC, 0, 3)}; |
| 13777 | |
| 13778 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13779 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13780 | arraysize(writes2)); |
| 13781 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13782 | |
| 13783 | AddSSLSocketData(); |
| 13784 | |
| 13785 | // Preload mail.example.org into HostCache. |
| 13786 | HostPortPair host_port("mail.example.org", 443); |
| 13787 | HostResolver::RequestInfo resolve_info(host_port); |
| 13788 | AddressList ignored; |
| 13789 | std::unique_ptr<HostResolver::Request> request; |
| 13790 | TestCompletionCallback callback; |
| 13791 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13792 | &ignored, callback.callback(), |
| 13793 | &request, NetLogWithSource()); |
| 13794 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13795 | rv = callback.WaitForResult(); |
| 13796 | EXPECT_THAT(rv, IsOk()); |
| 13797 | |
| 13798 | HttpRequestInfo request1; |
| 13799 | request1.method = "GET"; |
| 13800 | request1.url = GURL("https://www.example.org/"); |
| 13801 | request1.load_flags = 0; |
| 13802 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13803 | |
| 13804 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 13805 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13806 | rv = callback.WaitForResult(); |
| 13807 | EXPECT_THAT(rv, IsOk()); |
| 13808 | |
| 13809 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13810 | ASSERT_TRUE(response); |
| 13811 | ASSERT_TRUE(response->headers); |
| 13812 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13813 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13814 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13815 | std::string response_data; |
| 13816 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 13817 | EXPECT_EQ("hello!", response_data); |
| 13818 | |
| 13819 | HttpRequestInfo request2; |
| 13820 | request2.method = "GET"; |
| 13821 | request2.url = GURL("https://mail.example.org/"); |
| 13822 | request2.load_flags = 0; |
| 13823 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13824 | |
| 13825 | BoundTestNetLog log; |
| 13826 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 13827 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13828 | rv = callback.WaitForResult(); |
| 13829 | EXPECT_THAT(rv, IsOk()); |
| 13830 | |
| 13831 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 13832 | // caller. |
| 13833 | response = trans2.GetResponseInfo(); |
| 13834 | ASSERT_TRUE(response); |
| 13835 | ASSERT_TRUE(response->headers); |
| 13836 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 13837 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13838 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13839 | EXPECT_TRUE(response->ssl_info.cert); |
| 13840 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 13841 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13842 | } |
| 13843 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame^] | 13844 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13845 | public: |
| 13846 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame^] | 13847 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13848 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13849 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13850 | int ResolveFromCache(const RequestInfo& info, |
| 13851 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13852 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame^] | 13853 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13854 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame^] | 13855 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13856 | return rv; |
| 13857 | } |
| 13858 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13859 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13860 | const HostPortPair host_port_; |
| 13861 | }; |
| 13862 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13863 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13864 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13865 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame^] | 13866 | session_deps_.host_resolver = base::MakeUnique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13867 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13868 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13869 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13870 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13871 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13872 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13873 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13874 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13875 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13876 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13877 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13878 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13879 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13880 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13881 | SpdySerializedFrame host1_resp_body( |
| 13882 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13883 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13884 | SpdySerializedFrame host2_resp_body( |
| 13885 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13886 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13887 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13888 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13889 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13890 | }; |
| 13891 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13892 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13893 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13894 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13895 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13896 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13897 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13898 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13899 | HttpRequestInfo request1; |
| 13900 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13901 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13902 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13903 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13904 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13905 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13907 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13908 | |
| 13909 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13910 | ASSERT_TRUE(response); |
| 13911 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13912 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13913 | |
| 13914 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13915 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13916 | EXPECT_EQ("hello!", response_data); |
| 13917 | |
| 13918 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13919 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13920 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13921 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame^] | 13922 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13923 | &ignored, callback.callback(), |
| 13924 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13925 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13926 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13927 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13928 | |
| 13929 | HttpRequestInfo request2; |
| 13930 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13931 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13932 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13933 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13934 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13935 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13936 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13937 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13938 | |
| 13939 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13940 | ASSERT_TRUE(response); |
| 13941 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13942 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13943 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13944 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13945 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13946 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13947 | } |
| 13948 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13949 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13950 | const std::string https_url = "https://www.example.org:8080/"; |
| 13951 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13952 | |
| 13953 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13954 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13955 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13956 | |
| 13957 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13958 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13959 | }; |
| 13960 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13961 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13962 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13963 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13964 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13965 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13966 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13967 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13968 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13969 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13970 | |
| 13971 | // HTTP GET for the HTTP URL |
| 13972 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13973 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13974 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13975 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13976 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13977 | }; |
| 13978 | |
| 13979 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13980 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13981 | MockRead(ASYNC, 2, "hello"), |
| 13982 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13983 | }; |
| 13984 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13985 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13986 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13987 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13988 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13989 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13991 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13992 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13993 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13994 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13995 | |
| 13996 | // Start the first transaction to set up the SpdySession |
| 13997 | HttpRequestInfo request1; |
| 13998 | request1.method = "GET"; |
| 13999 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14000 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14001 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14002 | TestCompletionCallback callback1; |
| 14003 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14004 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14005 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14006 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14007 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14008 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14009 | |
| 14010 | // Now, start the HTTP request |
| 14011 | HttpRequestInfo request2; |
| 14012 | request2.method = "GET"; |
| 14013 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14014 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14015 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14016 | TestCompletionCallback callback2; |
| 14017 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14018 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14019 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14020 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14021 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14022 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14023 | } |
| 14024 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14025 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 14026 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14027 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14028 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14029 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14030 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14031 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14032 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14033 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14034 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14035 | |
| 14036 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14037 | // negotiated. |
| 14038 | StaticSocketDataProvider data; |
| 14039 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14040 | |
| 14041 | // 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] | 14042 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14043 | // mocked. This way the request relies on the alternate Job. |
| 14044 | StaticSocketDataProvider data_refused; |
| 14045 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14046 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14047 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14048 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14049 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14050 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14051 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14052 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14053 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14054 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 14055 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14056 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14057 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14058 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14059 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14060 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14061 | TestCompletionCallback callback; |
| 14062 | |
| 14063 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14064 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14065 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14066 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14067 | } |
| 14068 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14069 | // 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] | 14070 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14071 | // succeeds, the request should succeed, even if the latter fails because |
| 14072 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14073 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14074 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14075 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14076 | |
| 14077 | // Negotiate HTTP/1.1 with alternative. |
| 14078 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14079 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14080 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 14081 | |
| 14082 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14083 | // negotiated. |
| 14084 | StaticSocketDataProvider data; |
| 14085 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14086 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14087 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14088 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14089 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14090 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 14091 | |
| 14092 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14093 | MockWrite("GET / HTTP/1.1\r\n" |
| 14094 | "Host: www.example.org\r\n" |
| 14095 | "Connection: keep-alive\r\n\r\n"), |
| 14096 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14097 | "Host: www.example.org\r\n" |
| 14098 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14099 | }; |
| 14100 | |
| 14101 | MockRead http_reads[] = { |
| 14102 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14103 | MockRead("Content-Type: text/html\r\n"), |
| 14104 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14105 | MockRead("foobar"), |
| 14106 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14107 | MockRead("Content-Type: text/html\r\n"), |
| 14108 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14109 | MockRead("another"), |
| 14110 | }; |
| 14111 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14112 | http_writes, arraysize(http_writes)); |
| 14113 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14114 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14115 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14116 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14117 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14118 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14119 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14120 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14121 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 14122 | expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14123 | |
| 14124 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14125 | HttpRequestInfo request1; |
| 14126 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14127 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14128 | request1.load_flags = 0; |
| 14129 | TestCompletionCallback callback1; |
| 14130 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14131 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14132 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14133 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14134 | |
| 14135 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14136 | ASSERT_TRUE(response1); |
| 14137 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14138 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14139 | |
| 14140 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14141 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14142 | EXPECT_EQ("foobar", response_data1); |
| 14143 | |
| 14144 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14145 | // for alternative service. |
| 14146 | EXPECT_TRUE( |
| 14147 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14148 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14149 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14150 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14151 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14152 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14153 | HttpRequestInfo request2; |
| 14154 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14155 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14156 | request2.load_flags = 0; |
| 14157 | TestCompletionCallback callback2; |
| 14158 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14159 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14160 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14161 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14162 | |
| 14163 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14164 | ASSERT_TRUE(response2); |
| 14165 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14166 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14167 | |
| 14168 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14169 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14170 | EXPECT_EQ("another", response_data2); |
| 14171 | } |
| 14172 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14173 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14174 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14175 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14176 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14177 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14178 | HostPortPair alternative("alternative.example.org", 443); |
| 14179 | std::string origin_url = "https://origin.example.org:443"; |
| 14180 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14181 | |
| 14182 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14183 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14184 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14185 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14186 | |
| 14187 | // HTTP/1.1 data for |request1| and |request2|. |
| 14188 | MockWrite http_writes[] = { |
| 14189 | MockWrite( |
| 14190 | "GET / HTTP/1.1\r\n" |
| 14191 | "Host: alternative.example.org\r\n" |
| 14192 | "Connection: keep-alive\r\n\r\n"), |
| 14193 | MockWrite( |
| 14194 | "GET / HTTP/1.1\r\n" |
| 14195 | "Host: alternative.example.org\r\n" |
| 14196 | "Connection: keep-alive\r\n\r\n"), |
| 14197 | }; |
| 14198 | |
| 14199 | MockRead http_reads[] = { |
| 14200 | MockRead( |
| 14201 | "HTTP/1.1 200 OK\r\n" |
| 14202 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14203 | "Content-Length: 40\r\n\r\n" |
| 14204 | "first HTTP/1.1 response from alternative"), |
| 14205 | MockRead( |
| 14206 | "HTTP/1.1 200 OK\r\n" |
| 14207 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14208 | "Content-Length: 41\r\n\r\n" |
| 14209 | "second HTTP/1.1 response from alternative"), |
| 14210 | }; |
| 14211 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14212 | http_writes, arraysize(http_writes)); |
| 14213 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14214 | |
| 14215 | // This test documents that an alternate Job should not pool to an already |
| 14216 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14217 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14218 | StaticSocketDataProvider data_refused; |
| 14219 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14220 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14221 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14222 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14223 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14224 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14225 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14226 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14227 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14228 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 14229 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14230 | |
| 14231 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14232 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14233 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14234 | request1.method = "GET"; |
| 14235 | request1.url = GURL(alternative_url); |
| 14236 | request1.load_flags = 0; |
| 14237 | TestCompletionCallback callback1; |
| 14238 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14239 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14240 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14241 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14242 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14243 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14244 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14245 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14246 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14247 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14248 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14249 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14250 | |
| 14251 | // Request for origin.example.org, which has an alternative service. This |
| 14252 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14253 | // 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] | 14254 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14255 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14256 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14257 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14258 | request2.method = "GET"; |
| 14259 | request2.url = GURL(origin_url); |
| 14260 | request2.load_flags = 0; |
| 14261 | TestCompletionCallback callback2; |
| 14262 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14263 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14264 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14265 | |
| 14266 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14267 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14268 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14269 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14270 | request3.method = "GET"; |
| 14271 | request3.url = GURL(alternative_url); |
| 14272 | request3.load_flags = 0; |
| 14273 | TestCompletionCallback callback3; |
| 14274 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14275 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14276 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14277 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14278 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14279 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14280 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14281 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14282 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 14283 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14284 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14285 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 14286 | } |
| 14287 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14288 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14289 | const std::string https_url = "https://www.example.org:8080/"; |
| 14290 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14291 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14292 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14293 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14294 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14295 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14296 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14297 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14298 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14299 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14300 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14301 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14302 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 14303 | |
| 14304 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14305 | SpdyHeaderBlock req2_block; |
| 14306 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14307 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14308 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 14309 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14310 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14311 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14312 | |
| 14313 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14314 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 14315 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14316 | }; |
| 14317 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14318 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14319 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14320 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14321 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14322 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 14323 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14324 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14325 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14326 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14327 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14328 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14329 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14330 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14331 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14332 | CreateMockRead(wrapped_resp1, 4), |
| 14333 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14334 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14335 | CreateMockRead(resp2, 8), |
| 14336 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14337 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 14338 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14339 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14340 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14341 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14342 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14343 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14344 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14345 | session_deps_.proxy_service = |
| 14346 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14347 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14348 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14349 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14350 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14351 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14352 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14353 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14354 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14355 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14356 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14357 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14358 | |
| 14359 | // Start the first transaction to set up the SpdySession |
| 14360 | HttpRequestInfo request1; |
| 14361 | request1.method = "GET"; |
| 14362 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14363 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14364 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14365 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14366 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14367 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14368 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14369 | data1.RunUntilPaused(); |
| 14370 | base::RunLoop().RunUntilIdle(); |
| 14371 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14372 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14373 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14374 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14375 | LoadTimingInfo load_timing_info1; |
| 14376 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 14377 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 14378 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14379 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14380 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14381 | HttpRequestInfo request2; |
| 14382 | request2.method = "GET"; |
| 14383 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14384 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14385 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14386 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14387 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14388 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14389 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14390 | data1.RunUntilPaused(); |
| 14391 | base::RunLoop().RunUntilIdle(); |
| 14392 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14393 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14394 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14395 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14396 | |
| 14397 | LoadTimingInfo load_timing_info2; |
| 14398 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14399 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14400 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14401 | // HTTP requests over a SPDY session should have a different connection |
| 14402 | // socket_log_id than requests over a tunnel. |
| 14403 | 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] | 14404 | } |
| 14405 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14406 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14407 | // that we do not pool other origins that resolve to the same IP when |
| 14408 | // the certificate does not match the new origin. |
| 14409 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14410 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14411 | const std::string url1 = "http://www.example.org/"; |
| 14412 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14413 | const std::string ip_addr = "1.2.3.4"; |
| 14414 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14415 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14416 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14417 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14418 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 14419 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14420 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14421 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14422 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14423 | |
| 14424 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14425 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14426 | }; |
| 14427 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14428 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14429 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14430 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14431 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 14432 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14433 | }; |
| 14434 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14435 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14436 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14437 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14438 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14439 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14440 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14441 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14442 | |
| 14443 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14444 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14445 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14446 | |
| 14447 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14448 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14449 | }; |
| 14450 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14451 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14452 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 14453 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14454 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14455 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14456 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14457 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14458 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14459 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14460 | |
| 14461 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14462 | // all others direct. |
| 14463 | ProxyConfig proxy_config; |
| 14464 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14465 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 14466 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
| 14467 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14468 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14469 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14470 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14471 | // Load a valid cert. Note, that this does not need to |
| 14472 | // be valid for proxy because the MockSSLClientSocket does |
| 14473 | // not actually verify it. But SpdySession will use this |
| 14474 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14475 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14476 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14477 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14478 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14479 | |
| 14480 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14481 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14482 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14483 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14484 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14485 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14486 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14487 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14488 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14489 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14490 | |
| 14491 | // Start the first transaction to set up the SpdySession |
| 14492 | HttpRequestInfo request1; |
| 14493 | request1.method = "GET"; |
| 14494 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14495 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14496 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14497 | TestCompletionCallback callback1; |
| 14498 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14499 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14500 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14501 | data1.RunUntilPaused(); |
| 14502 | base::RunLoop().RunUntilIdle(); |
| 14503 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14504 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14505 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14506 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14507 | |
| 14508 | // Now, start the HTTP request |
| 14509 | HttpRequestInfo request2; |
| 14510 | request2.method = "GET"; |
| 14511 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14512 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14513 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14514 | TestCompletionCallback callback2; |
| 14515 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14516 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14517 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14518 | |
| 14519 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14520 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14521 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14522 | } |
| 14523 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14524 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14525 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14526 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14527 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14528 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14529 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14530 | |
| 14531 | MockRead reads1[] = { |
| 14532 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14533 | }; |
| 14534 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14535 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14536 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14537 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14538 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14539 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14540 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14541 | }; |
| 14542 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14543 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14544 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14545 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14546 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 14547 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14548 | }; |
| 14549 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14550 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14551 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14552 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14553 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14554 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14555 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14556 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14557 | |
| 14558 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14559 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14560 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14561 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14562 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14563 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14564 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14565 | |
| 14566 | // Start the first transaction to set up the SpdySession and verify that |
| 14567 | // connection was closed. |
| 14568 | HttpRequestInfo request1; |
| 14569 | request1.method = "GET"; |
| 14570 | request1.url = GURL(https_url); |
| 14571 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14572 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14573 | TestCompletionCallback callback1; |
| 14574 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14575 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14576 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14577 | |
| 14578 | // Now, start the second request and make sure it succeeds. |
| 14579 | HttpRequestInfo request2; |
| 14580 | request2.method = "GET"; |
| 14581 | request2.url = GURL(https_url); |
| 14582 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14583 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14584 | TestCompletionCallback callback2; |
| 14585 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14586 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14587 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14588 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14589 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14590 | } |
| 14591 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14592 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14593 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14594 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14595 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14596 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14597 | |
| 14598 | // Use two different hosts with different IPs so they don't get pooled. |
| 14599 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14600 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14601 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14602 | |
| 14603 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14604 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14605 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14606 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14607 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14608 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14609 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14610 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14611 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14612 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14613 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14614 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14615 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14616 | SpdySerializedFrame host1_resp_body( |
| 14617 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14618 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14619 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14620 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14621 | }; |
| 14622 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14623 | // Use a separate test instance for the separate SpdySession that will be |
| 14624 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14625 | SpdyTestUtil spdy_util_2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14626 | auto spdy1_data = base::MakeUnique<SequencedSocketData>( |
| 14627 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14628 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14629 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14630 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14631 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14632 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14633 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14634 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14635 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14636 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14637 | SpdySerializedFrame host2_resp_body( |
| 14638 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14639 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14640 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14641 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14642 | }; |
| 14643 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14644 | auto spdy2_data = base::MakeUnique<SequencedSocketData>( |
| 14645 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14646 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14647 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14648 | |
| 14649 | MockWrite http_write[] = { |
| 14650 | MockWrite("GET / HTTP/1.1\r\n" |
| 14651 | "Host: www.a.com\r\n" |
| 14652 | "Connection: keep-alive\r\n\r\n"), |
| 14653 | }; |
| 14654 | |
| 14655 | MockRead http_read[] = { |
| 14656 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14657 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14658 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14659 | MockRead("hello!"), |
| 14660 | }; |
| 14661 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14662 | http_write, arraysize(http_write)); |
| 14663 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14664 | |
| 14665 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14666 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14667 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14668 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14669 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14670 | |
| 14671 | TestCompletionCallback callback; |
| 14672 | HttpRequestInfo request1; |
| 14673 | request1.method = "GET"; |
| 14674 | request1.url = GURL("https://www.a.com/"); |
| 14675 | request1.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14676 | auto trans = |
| 14677 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14678 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14679 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14681 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14682 | |
| 14683 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14684 | ASSERT_TRUE(response); |
| 14685 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14686 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14687 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14688 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14689 | |
| 14690 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14691 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14692 | EXPECT_EQ("hello!", response_data); |
| 14693 | trans.reset(); |
| 14694 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14695 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14696 | |
| 14697 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14698 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14699 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14700 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14701 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14702 | HttpRequestInfo request2; |
| 14703 | request2.method = "GET"; |
| 14704 | request2.url = GURL("https://www.b.com/"); |
| 14705 | request2.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14706 | trans = |
| 14707 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14708 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14709 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14710 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14711 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14712 | |
| 14713 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14714 | ASSERT_TRUE(response); |
| 14715 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14716 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14717 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14718 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14719 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14720 | EXPECT_EQ("hello!", response_data); |
| 14721 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14722 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14723 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14724 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14725 | |
| 14726 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14727 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14728 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14729 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14730 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14731 | HttpRequestInfo request3; |
| 14732 | request3.method = "GET"; |
| 14733 | request3.url = GURL("http://www.a.com/"); |
| 14734 | request3.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14735 | trans = |
| 14736 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14737 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14738 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14739 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14740 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14741 | |
| 14742 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14743 | ASSERT_TRUE(response); |
| 14744 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14745 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14746 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14747 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14748 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14749 | EXPECT_EQ("hello!", response_data); |
| 14750 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14751 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14752 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14753 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14754 | } |
| 14755 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14756 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14757 | HttpRequestInfo request; |
| 14758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14759 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14760 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14761 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14762 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14763 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14764 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14765 | StaticSocketDataProvider data; |
| 14766 | data.set_connect_data(mock_connect); |
| 14767 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14768 | |
| 14769 | TestCompletionCallback callback; |
| 14770 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14771 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14772 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14773 | |
| 14774 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14775 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14776 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14777 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14778 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14779 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14780 | |
| 14781 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14782 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14783 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14784 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14785 | |
| 14786 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14787 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14788 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14789 | } |
| 14790 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14791 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14792 | HttpRequestInfo request; |
| 14793 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14794 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14795 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14796 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14797 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14798 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14799 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14800 | StaticSocketDataProvider data; |
| 14801 | data.set_connect_data(mock_connect); |
| 14802 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14803 | |
| 14804 | TestCompletionCallback callback; |
| 14805 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14806 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14807 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14808 | |
| 14809 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14810 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14811 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14812 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14813 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14814 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14815 | |
| 14816 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14817 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14818 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14819 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14820 | |
| 14821 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14822 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14823 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14824 | } |
| 14825 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14826 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14827 | HttpRequestInfo request; |
| 14828 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14829 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14830 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14832 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14833 | |
| 14834 | MockWrite data_writes[] = { |
| 14835 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14836 | }; |
| 14837 | MockRead data_reads[] = { |
| 14838 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14839 | }; |
| 14840 | |
| 14841 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14842 | data_writes, arraysize(data_writes)); |
| 14843 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14844 | |
| 14845 | TestCompletionCallback callback; |
| 14846 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14847 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14848 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14849 | |
| 14850 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14851 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14852 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14853 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14854 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14855 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14856 | } |
| 14857 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14858 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14859 | HttpRequestInfo request; |
| 14860 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14861 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14862 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14863 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14864 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14865 | |
| 14866 | MockWrite data_writes[] = { |
| 14867 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14868 | }; |
| 14869 | MockRead data_reads[] = { |
| 14870 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14871 | }; |
| 14872 | |
| 14873 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14874 | data_writes, arraysize(data_writes)); |
| 14875 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14876 | |
| 14877 | TestCompletionCallback callback; |
| 14878 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14879 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14881 | |
| 14882 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14883 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14884 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14885 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14886 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14887 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14888 | } |
| 14889 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14890 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14891 | HttpRequestInfo request; |
| 14892 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14893 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14894 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14895 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14896 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14897 | |
| 14898 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14899 | MockWrite( |
| 14900 | "GET / HTTP/1.1\r\n" |
| 14901 | "Host: www.example.org\r\n" |
| 14902 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14903 | }; |
| 14904 | MockRead data_reads[] = { |
| 14905 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14906 | }; |
| 14907 | |
| 14908 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14909 | data_writes, arraysize(data_writes)); |
| 14910 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14911 | |
| 14912 | TestCompletionCallback callback; |
| 14913 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14914 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14915 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14916 | |
| 14917 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14918 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14919 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14920 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14921 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14922 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14923 | } |
| 14924 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14925 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14926 | HttpRequestInfo request; |
| 14927 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14928 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14929 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14930 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14931 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14932 | |
| 14933 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14934 | MockWrite( |
| 14935 | "GET / HTTP/1.1\r\n" |
| 14936 | "Host: www.example.org\r\n" |
| 14937 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14938 | }; |
| 14939 | MockRead data_reads[] = { |
| 14940 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14941 | }; |
| 14942 | |
| 14943 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14944 | data_writes, arraysize(data_writes)); |
| 14945 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14946 | |
| 14947 | TestCompletionCallback callback; |
| 14948 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14949 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14950 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14951 | |
| 14952 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14953 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14954 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14955 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14956 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14957 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14958 | } |
| 14959 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14960 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14961 | HttpRequestInfo request; |
| 14962 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14963 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14964 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14965 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14966 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14967 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14968 | |
| 14969 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14970 | MockWrite( |
| 14971 | "GET / HTTP/1.1\r\n" |
| 14972 | "Host: www.example.org\r\n" |
| 14973 | "Connection: keep-alive\r\n" |
| 14974 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14975 | }; |
| 14976 | MockRead data_reads[] = { |
| 14977 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14978 | "Content-Length: 5\r\n\r\n" |
| 14979 | "hello"), |
| 14980 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14981 | }; |
| 14982 | |
| 14983 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14984 | data_writes, arraysize(data_writes)); |
| 14985 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14986 | |
| 14987 | TestCompletionCallback callback; |
| 14988 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14989 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14990 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14991 | |
| 14992 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14993 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14994 | |
| 14995 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14996 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14997 | std::string foo; |
| 14998 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14999 | EXPECT_EQ("bar", foo); |
| 15000 | } |
| 15001 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15002 | namespace { |
| 15003 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15004 | // Fake HttpStream that simply records calls to SetPriority(). |
| 15005 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15006 | public base::SupportsWeakPtr<FakeStream> { |
| 15007 | public: |
| 15008 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15009 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15010 | |
| 15011 | RequestPriority priority() const { return priority_; } |
| 15012 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15013 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15014 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15015 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15016 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15017 | return ERR_IO_PENDING; |
| 15018 | } |
| 15019 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15020 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15021 | HttpResponseInfo* response, |
| 15022 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15023 | ADD_FAILURE(); |
| 15024 | return ERR_UNEXPECTED; |
| 15025 | } |
| 15026 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15027 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15028 | ADD_FAILURE(); |
| 15029 | return ERR_UNEXPECTED; |
| 15030 | } |
| 15031 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15032 | int ReadResponseBody(IOBuffer* buf, |
| 15033 | int buf_len, |
| 15034 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15035 | ADD_FAILURE(); |
| 15036 | return ERR_UNEXPECTED; |
| 15037 | } |
| 15038 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15039 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15040 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15041 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15042 | ADD_FAILURE(); |
| 15043 | return false; |
| 15044 | } |
| 15045 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15046 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15047 | ADD_FAILURE(); |
| 15048 | return false; |
| 15049 | } |
| 15050 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15051 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15052 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15053 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15054 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15055 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 15056 | ADD_FAILURE(); |
| 15057 | return 0; |
| 15058 | } |
| 15059 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15060 | int64_t GetTotalSentBytes() const override { |
| 15061 | ADD_FAILURE(); |
| 15062 | return 0; |
| 15063 | } |
| 15064 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15065 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15066 | ADD_FAILURE(); |
| 15067 | return false; |
| 15068 | } |
| 15069 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15070 | bool GetAlternativeService( |
| 15071 | AlternativeService* alternative_service) const override { |
| 15072 | ADD_FAILURE(); |
| 15073 | return false; |
| 15074 | } |
| 15075 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15076 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 15077 | |
| 15078 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15079 | ADD_FAILURE(); |
| 15080 | } |
| 15081 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15082 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15083 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15084 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15085 | TokenBindingType tb_type, |
| 15086 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15087 | ADD_FAILURE(); |
| 15088 | return ERR_NOT_IMPLEMENTED; |
| 15089 | } |
| 15090 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15091 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15092 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15093 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15094 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15095 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15096 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15097 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15098 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15099 | private: |
| 15100 | RequestPriority priority_; |
| 15101 | |
| 15102 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15103 | }; |
| 15104 | |
| 15105 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15106 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15107 | class FakeStreamRequest : public HttpStreamRequest, |
| 15108 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15109 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15110 | FakeStreamRequest(RequestPriority priority, |
| 15111 | HttpStreamRequest::Delegate* delegate) |
| 15112 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15113 | delegate_(delegate), |
| 15114 | websocket_stream_create_helper_(NULL) {} |
| 15115 | |
| 15116 | FakeStreamRequest(RequestPriority priority, |
| 15117 | HttpStreamRequest::Delegate* delegate, |
| 15118 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15119 | : priority_(priority), |
| 15120 | delegate_(delegate), |
| 15121 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15122 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15123 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15124 | |
| 15125 | RequestPriority priority() const { return priority_; } |
| 15126 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15127 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15128 | websocket_stream_create_helper() const { |
| 15129 | return websocket_stream_create_helper_; |
| 15130 | } |
| 15131 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15132 | // Create a new FakeStream and pass it to the request's |
| 15133 | // delegate. Returns a weak pointer to the FakeStream. |
| 15134 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 15135 | FakeStream* fake_stream = new FakeStream(priority_); |
| 15136 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15137 | // immediately delete |fake_stream|. |
| 15138 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 15139 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 15140 | return weak_stream; |
| 15141 | } |
| 15142 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15143 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15144 | ADD_FAILURE(); |
| 15145 | return ERR_UNEXPECTED; |
| 15146 | } |
| 15147 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15148 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15149 | ADD_FAILURE(); |
| 15150 | return LoadState(); |
| 15151 | } |
| 15152 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15153 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15154 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15155 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15156 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15157 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15158 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15159 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15160 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15161 | const ConnectionAttempts& connection_attempts() const override { |
| 15162 | static ConnectionAttempts no_attempts; |
| 15163 | return no_attempts; |
| 15164 | } |
| 15165 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15166 | private: |
| 15167 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15168 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15169 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15170 | |
| 15171 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15172 | }; |
| 15173 | |
| 15174 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15175 | class FakeStreamFactory : public HttpStreamFactory { |
| 15176 | public: |
| 15177 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15178 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15179 | |
| 15180 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15181 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15182 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15183 | return last_stream_request_; |
| 15184 | } |
| 15185 | |
xunjieli | 8fb01a7 | 2017-05-22 18:38:00 | [diff] [blame] | 15186 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 15187 | RequestPriority priority, |
| 15188 | const SSLConfig& server_ssl_config, |
| 15189 | const SSLConfig& proxy_ssl_config, |
| 15190 | HttpStreamRequest::Delegate* delegate, |
| 15191 | bool enable_ip_based_pooling, |
| 15192 | bool enable_alternative_services, |
| 15193 | const NetLogWithSource& net_log) override { |
| 15194 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15195 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 8fb01a7 | 2017-05-22 18:38:00 | [diff] [blame] | 15196 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15197 | } |
| 15198 | |
xunjieli | 8fb01a7 | 2017-05-22 18:38:00 | [diff] [blame] | 15199 | HttpStreamRequest* RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15200 | const HttpRequestInfo& info, |
| 15201 | RequestPriority priority, |
| 15202 | const SSLConfig& server_ssl_config, |
| 15203 | const SSLConfig& proxy_ssl_config, |
| 15204 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15205 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15206 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15207 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15208 | NOTREACHED(); |
| 15209 | return nullptr; |
| 15210 | } |
| 15211 | |
xunjieli | 8fb01a7 | 2017-05-22 18:38:00 | [diff] [blame] | 15212 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15213 | const HttpRequestInfo& info, |
| 15214 | RequestPriority priority, |
| 15215 | const SSLConfig& server_ssl_config, |
| 15216 | const SSLConfig& proxy_ssl_config, |
| 15217 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15218 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15219 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15220 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15221 | const NetLogWithSource& net_log) override { |
xunjieli | 8fb01a7 | 2017-05-22 18:38:00 | [diff] [blame] | 15222 | FakeStreamRequest* fake_request = |
| 15223 | new FakeStreamRequest(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15224 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 8fb01a7 | 2017-05-22 18:38:00 | [diff] [blame] | 15225 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15226 | } |
| 15227 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15228 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15229 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15230 | ADD_FAILURE(); |
| 15231 | } |
| 15232 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15233 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15234 | ADD_FAILURE(); |
| 15235 | return NULL; |
| 15236 | } |
| 15237 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15238 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15239 | const std::string& parent_absolute_name) const override { |
| 15240 | ADD_FAILURE(); |
| 15241 | } |
| 15242 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15243 | private: |
| 15244 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15245 | |
| 15246 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15247 | }; |
| 15248 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15249 | // TODO(ricea): Maybe unify this with the one in |
| 15250 | // url_request_http_job_unittest.cc ? |
| 15251 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15252 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15253 | FakeWebSocketBasicHandshakeStream( |
| 15254 | std::unique_ptr<ClientSocketHandle> connection, |
| 15255 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15256 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15257 | |
| 15258 | // Fake implementation of HttpStreamBase methods. |
| 15259 | // This ends up being quite "real" because this object has to really send data |
| 15260 | // on the mock socket. It might be easier to use the real implementation, but |
| 15261 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15262 | // difficult. |
| 15263 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15264 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15265 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15266 | const CompletionCallback& callback) override { |
| 15267 | state_.Initialize(request_info, priority, net_log, callback); |
| 15268 | return OK; |
| 15269 | } |
| 15270 | |
| 15271 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15272 | HttpResponseInfo* response, |
| 15273 | const CompletionCallback& callback) override { |
| 15274 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 15275 | response, callback); |
| 15276 | } |
| 15277 | |
| 15278 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 15279 | return parser()->ReadResponseHeaders(callback); |
| 15280 | } |
| 15281 | |
| 15282 | int ReadResponseBody(IOBuffer* buf, |
| 15283 | int buf_len, |
| 15284 | const CompletionCallback& callback) override { |
| 15285 | NOTREACHED(); |
| 15286 | return ERR_IO_PENDING; |
| 15287 | } |
| 15288 | |
| 15289 | void Close(bool not_reusable) override { |
| 15290 | if (parser()) |
| 15291 | parser()->Close(true); |
| 15292 | } |
| 15293 | |
| 15294 | bool IsResponseBodyComplete() const override { |
| 15295 | NOTREACHED(); |
| 15296 | return false; |
| 15297 | } |
| 15298 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15299 | bool IsConnectionReused() const override { |
| 15300 | NOTREACHED(); |
| 15301 | return false; |
| 15302 | } |
| 15303 | void SetConnectionReused() override { NOTREACHED(); } |
| 15304 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15305 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15306 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15307 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15308 | NOTREACHED(); |
| 15309 | return 0; |
| 15310 | } |
| 15311 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15312 | int64_t GetTotalSentBytes() const override { |
| 15313 | NOTREACHED(); |
| 15314 | return 0; |
| 15315 | } |
| 15316 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15317 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 15318 | NOTREACHED(); |
| 15319 | return false; |
| 15320 | } |
| 15321 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15322 | bool GetAlternativeService( |
| 15323 | AlternativeService* alternative_service) const override { |
| 15324 | ADD_FAILURE(); |
| 15325 | return false; |
| 15326 | } |
| 15327 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 15328 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15329 | |
| 15330 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 15331 | NOTREACHED(); |
| 15332 | } |
| 15333 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15334 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15335 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15336 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15337 | TokenBindingType tb_type, |
| 15338 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15339 | ADD_FAILURE(); |
| 15340 | return ERR_NOT_IMPLEMENTED; |
| 15341 | } |
| 15342 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15343 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 15344 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15345 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15346 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15347 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 15348 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15349 | HttpStream* RenewStreamForAuth() override { |
| 15350 | NOTREACHED(); |
| 15351 | return nullptr; |
| 15352 | } |
| 15353 | |
| 15354 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15355 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15356 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15357 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15358 | } |
| 15359 | |
| 15360 | private: |
| 15361 | HttpStreamParser* parser() const { return state_.parser(); } |
| 15362 | HttpBasicState state_; |
| 15363 | |
| 15364 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 15365 | }; |
| 15366 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15367 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 15368 | // worth doing. |
| 15369 | class FakeWebSocketStreamCreateHelper : |
| 15370 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 15371 | public: |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15372 | std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15373 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15374 | bool using_proxy) override { |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15375 | return base::MakeUnique<FakeWebSocketBasicHandshakeStream>( |
| 15376 | std::move(connection), using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15377 | } |
| 15378 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15379 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15380 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15381 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15382 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15383 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15384 | } |
| 15385 | }; |
| 15386 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15387 | } // namespace |
| 15388 | |
| 15389 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15390 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15391 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15393 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15394 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15395 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15396 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15397 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15398 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15399 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15400 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15401 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15402 | TestCompletionCallback callback; |
| 15403 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15404 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15405 | |
| 15406 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15407 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15408 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15409 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15410 | } |
| 15411 | |
| 15412 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15413 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15414 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15416 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15417 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15418 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15419 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15420 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15421 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15422 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15423 | TestCompletionCallback callback; |
| 15424 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15425 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15426 | |
| 15427 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15428 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15429 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15430 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15431 | |
| 15432 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15433 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15434 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15435 | } |
| 15436 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15437 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15438 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15439 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15440 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15441 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15442 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15443 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15444 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15445 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15446 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15447 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15448 | TestCompletionCallback callback; |
| 15449 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15450 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15451 | |
| 15452 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15453 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15454 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15455 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15456 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15457 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15458 | |
| 15459 | trans.SetPriority(LOWEST); |
| 15460 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15461 | } |
| 15462 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15463 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15464 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15465 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15466 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15467 | std::string test_cases[] = {"ws://www.example.org/", |
| 15468 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15469 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15470 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15471 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15472 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15473 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15474 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15475 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15476 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15477 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15478 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15479 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15480 | &websocket_stream_create_helper); |
| 15481 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15482 | TestCompletionCallback callback; |
| 15483 | request.method = "GET"; |
| 15484 | request.url = GURL(test_cases[i]); |
| 15485 | |
| 15486 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15487 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15488 | |
| 15489 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15490 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15491 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15492 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15493 | fake_request->websocket_stream_create_helper()); |
| 15494 | } |
| 15495 | } |
| 15496 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15497 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15498 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15499 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15500 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15501 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15502 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15503 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15504 | |
| 15505 | // Set up SSL request. |
| 15506 | |
| 15507 | HttpRequestInfo ssl_request; |
| 15508 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15509 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15510 | |
| 15511 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15512 | MockWrite( |
| 15513 | "GET / HTTP/1.1\r\n" |
| 15514 | "Host: www.example.org\r\n" |
| 15515 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15516 | }; |
| 15517 | MockRead ssl_reads[] = { |
| 15518 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15519 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15520 | MockRead("hello world"), |
| 15521 | MockRead(SYNCHRONOUS, OK), |
| 15522 | }; |
| 15523 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15524 | ssl_writes, arraysize(ssl_writes)); |
| 15525 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15526 | |
| 15527 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15528 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15529 | |
| 15530 | // Set up HTTP request. |
| 15531 | |
| 15532 | HttpRequestInfo http_request; |
| 15533 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15534 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15535 | |
| 15536 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15537 | MockWrite( |
| 15538 | "GET / HTTP/1.1\r\n" |
| 15539 | "Host: www.example.org\r\n" |
| 15540 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15541 | }; |
| 15542 | MockRead http_reads[] = { |
| 15543 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15544 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15545 | MockRead("falafel"), |
| 15546 | MockRead(SYNCHRONOUS, OK), |
| 15547 | }; |
| 15548 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15549 | http_writes, arraysize(http_writes)); |
| 15550 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15551 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15553 | |
| 15554 | // Start the SSL request. |
| 15555 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15556 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15557 | ASSERT_EQ(ERR_IO_PENDING, |
| 15558 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 15559 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15560 | |
| 15561 | // Start the HTTP request. Pool should stall. |
| 15562 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15563 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15564 | ASSERT_EQ(ERR_IO_PENDING, |
| 15565 | http_trans.Start(&http_request, http_callback.callback(), |
| 15566 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15567 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15568 | |
| 15569 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15570 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15571 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15572 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15573 | EXPECT_EQ("hello world", response_data); |
| 15574 | |
| 15575 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15576 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15577 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15578 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15579 | |
| 15580 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15581 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15582 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15583 | EXPECT_EQ("falafel", response_data); |
| 15584 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15585 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15586 | } |
| 15587 | |
| 15588 | // Tests that when a SSL connection is established but there's no corresponding |
| 15589 | // request that needs it, the new socket is closed if the transport socket pool |
| 15590 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15591 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15592 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15593 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15594 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15595 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15596 | |
| 15597 | // Set up an ssl request. |
| 15598 | |
| 15599 | HttpRequestInfo ssl_request; |
| 15600 | ssl_request.method = "GET"; |
| 15601 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15602 | |
| 15603 | // No data will be sent on the SSL socket. |
| 15604 | StaticSocketDataProvider ssl_data; |
| 15605 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15606 | |
| 15607 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15608 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15609 | |
| 15610 | // Set up HTTP request. |
| 15611 | |
| 15612 | HttpRequestInfo http_request; |
| 15613 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15614 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15615 | |
| 15616 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15617 | MockWrite( |
| 15618 | "GET / HTTP/1.1\r\n" |
| 15619 | "Host: www.example.org\r\n" |
| 15620 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15621 | }; |
| 15622 | MockRead http_reads[] = { |
| 15623 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15624 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15625 | MockRead("falafel"), |
| 15626 | MockRead(SYNCHRONOUS, OK), |
| 15627 | }; |
| 15628 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15629 | http_writes, arraysize(http_writes)); |
| 15630 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15631 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15632 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15633 | |
| 15634 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15635 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15636 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15637 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15638 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15639 | |
| 15640 | // Start the HTTP request. Pool should stall. |
| 15641 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15642 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15643 | ASSERT_EQ(ERR_IO_PENDING, |
| 15644 | http_trans.Start(&http_request, http_callback.callback(), |
| 15645 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15646 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15647 | |
| 15648 | // The SSL connection will automatically be closed once the connection is |
| 15649 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15650 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15651 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15652 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15653 | EXPECT_EQ("falafel", response_data); |
| 15654 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15655 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15656 | } |
| 15657 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15658 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15659 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15660 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15661 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15662 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15663 | |
| 15664 | HttpRequestInfo request; |
| 15665 | request.method = "POST"; |
| 15666 | request.url = GURL("http://www.foo.com/"); |
| 15667 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15668 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15669 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15670 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15671 | // Send headers successfully, but get an error while sending the body. |
| 15672 | MockWrite data_writes[] = { |
| 15673 | MockWrite("POST / HTTP/1.1\r\n" |
| 15674 | "Host: www.foo.com\r\n" |
| 15675 | "Connection: keep-alive\r\n" |
| 15676 | "Content-Length: 3\r\n\r\n"), |
| 15677 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15678 | }; |
| 15679 | |
| 15680 | MockRead data_reads[] = { |
| 15681 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15682 | MockRead("hello world"), |
| 15683 | MockRead(SYNCHRONOUS, OK), |
| 15684 | }; |
| 15685 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15686 | arraysize(data_writes)); |
| 15687 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15688 | |
| 15689 | TestCompletionCallback callback; |
| 15690 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15691 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15692 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15693 | |
| 15694 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15695 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15696 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15697 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15698 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15699 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15700 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15701 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15702 | |
| 15703 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15704 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15705 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15706 | EXPECT_EQ("hello world", response_data); |
| 15707 | } |
| 15708 | |
| 15709 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15710 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15711 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15712 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15713 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15714 | MockWrite data_writes[] = { |
| 15715 | MockWrite("GET / HTTP/1.1\r\n" |
| 15716 | "Host: www.foo.com\r\n" |
| 15717 | "Connection: keep-alive\r\n\r\n"), |
| 15718 | MockWrite("POST / HTTP/1.1\r\n" |
| 15719 | "Host: www.foo.com\r\n" |
| 15720 | "Connection: keep-alive\r\n" |
| 15721 | "Content-Length: 3\r\n\r\n"), |
| 15722 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15723 | }; |
| 15724 | |
| 15725 | MockRead data_reads[] = { |
| 15726 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15727 | "Content-Length: 14\r\n\r\n"), |
| 15728 | MockRead("first response"), |
| 15729 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15730 | "Content-Length: 15\r\n\r\n"), |
| 15731 | MockRead("second response"), |
| 15732 | MockRead(SYNCHRONOUS, OK), |
| 15733 | }; |
| 15734 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15735 | arraysize(data_writes)); |
| 15736 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15737 | |
| 15738 | TestCompletionCallback callback; |
| 15739 | HttpRequestInfo request1; |
| 15740 | request1.method = "GET"; |
| 15741 | request1.url = GURL("http://www.foo.com/"); |
| 15742 | request1.load_flags = 0; |
| 15743 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15744 | auto trans1 = |
| 15745 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15746 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15748 | |
| 15749 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15750 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15751 | |
| 15752 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15753 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15754 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15755 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15756 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15757 | |
| 15758 | std::string response_data1; |
| 15759 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15760 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15761 | EXPECT_EQ("first response", response_data1); |
| 15762 | // Delete the transaction to release the socket back into the socket pool. |
| 15763 | trans1.reset(); |
| 15764 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15765 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15766 | element_readers.push_back( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15767 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15768 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15769 | |
| 15770 | HttpRequestInfo request2; |
| 15771 | request2.method = "POST"; |
| 15772 | request2.url = GURL("http://www.foo.com/"); |
| 15773 | request2.upload_data_stream = &upload_data_stream; |
| 15774 | request2.load_flags = 0; |
| 15775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15776 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15777 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15778 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15779 | |
| 15780 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15781 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15782 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15783 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15784 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15785 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15786 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15787 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15788 | |
| 15789 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15790 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15791 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15792 | EXPECT_EQ("second response", response_data2); |
| 15793 | } |
| 15794 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15795 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15796 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15797 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15798 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15799 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15800 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15801 | |
| 15802 | HttpRequestInfo request; |
| 15803 | request.method = "POST"; |
| 15804 | request.url = GURL("http://www.foo.com/"); |
| 15805 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15806 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15807 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15808 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15809 | // Send headers successfully, but get an error while sending the body. |
| 15810 | MockWrite data_writes[] = { |
| 15811 | MockWrite("POST / HTTP/1.1\r\n" |
| 15812 | "Host: www.foo.com\r\n" |
| 15813 | "Connection: keep-alive\r\n" |
| 15814 | "Content-Length: 3\r\n\r\n" |
| 15815 | "fo"), |
| 15816 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15817 | }; |
| 15818 | |
| 15819 | MockRead data_reads[] = { |
| 15820 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15821 | MockRead("hello world"), |
| 15822 | MockRead(SYNCHRONOUS, OK), |
| 15823 | }; |
| 15824 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15825 | arraysize(data_writes)); |
| 15826 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15827 | |
| 15828 | TestCompletionCallback callback; |
| 15829 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15830 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15831 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15832 | |
| 15833 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15834 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15835 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15836 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15837 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15838 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15839 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15840 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15841 | |
| 15842 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15843 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15844 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15845 | EXPECT_EQ("hello world", response_data); |
| 15846 | } |
| 15847 | |
| 15848 | // This tests the more common case than the previous test, where headers and |
| 15849 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15850 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15851 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15852 | |
| 15853 | HttpRequestInfo request; |
| 15854 | request.method = "POST"; |
| 15855 | request.url = GURL("http://www.foo.com/"); |
| 15856 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15857 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15858 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15859 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15860 | // Send headers successfully, but get an error while sending the body. |
| 15861 | MockWrite data_writes[] = { |
| 15862 | MockWrite("POST / HTTP/1.1\r\n" |
| 15863 | "Host: www.foo.com\r\n" |
| 15864 | "Connection: keep-alive\r\n" |
| 15865 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15866 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15867 | }; |
| 15868 | |
| 15869 | MockRead data_reads[] = { |
| 15870 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15871 | MockRead("hello world"), |
| 15872 | MockRead(SYNCHRONOUS, OK), |
| 15873 | }; |
| 15874 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15875 | arraysize(data_writes)); |
| 15876 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15877 | |
| 15878 | TestCompletionCallback callback; |
| 15879 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15880 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15882 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15883 | // they can't be merged with the body in a single send. Not currently |
| 15884 | // necessary since a chunked body is never merged with headers, but this makes |
| 15885 | // the test more future proof. |
| 15886 | base::RunLoop().RunUntilIdle(); |
| 15887 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15888 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15889 | |
| 15890 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15891 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15892 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15893 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15894 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15895 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15896 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15897 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15898 | |
| 15899 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15900 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15901 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15902 | EXPECT_EQ("hello world", response_data); |
| 15903 | } |
| 15904 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15905 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15906 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15907 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15908 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15909 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15910 | |
| 15911 | HttpRequestInfo request; |
| 15912 | request.method = "POST"; |
| 15913 | request.url = GURL("http://www.foo.com/"); |
| 15914 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15915 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15916 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15917 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15918 | |
| 15919 | MockWrite data_writes[] = { |
| 15920 | MockWrite("POST / HTTP/1.1\r\n" |
| 15921 | "Host: www.foo.com\r\n" |
| 15922 | "Connection: keep-alive\r\n" |
| 15923 | "Content-Length: 3\r\n\r\n"), |
| 15924 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15925 | }; |
| 15926 | |
| 15927 | MockRead data_reads[] = { |
| 15928 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15929 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15930 | MockRead("hello world"), |
| 15931 | MockRead(SYNCHRONOUS, OK), |
| 15932 | }; |
| 15933 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15934 | arraysize(data_writes)); |
| 15935 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15936 | |
| 15937 | TestCompletionCallback callback; |
| 15938 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15939 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15941 | |
| 15942 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15943 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15945 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15946 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15947 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15948 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15949 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15950 | |
| 15951 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15952 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15953 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15954 | EXPECT_EQ("hello world", response_data); |
| 15955 | } |
| 15956 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15957 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15958 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15959 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15960 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15961 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15962 | |
| 15963 | HttpRequestInfo request; |
| 15964 | request.method = "POST"; |
| 15965 | request.url = GURL("http://www.foo.com/"); |
| 15966 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15967 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15969 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15970 | // Send headers successfully, but get an error while sending the body. |
| 15971 | MockWrite data_writes[] = { |
| 15972 | MockWrite("POST / HTTP/1.1\r\n" |
| 15973 | "Host: www.foo.com\r\n" |
| 15974 | "Connection: keep-alive\r\n" |
| 15975 | "Content-Length: 3\r\n\r\n"), |
| 15976 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15977 | }; |
| 15978 | |
| 15979 | MockRead data_reads[] = { |
| 15980 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15981 | MockRead("hello world"), |
| 15982 | MockRead(SYNCHRONOUS, OK), |
| 15983 | }; |
| 15984 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15985 | arraysize(data_writes)); |
| 15986 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15987 | |
| 15988 | TestCompletionCallback callback; |
| 15989 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15990 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15991 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15992 | |
| 15993 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15994 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15995 | } |
| 15996 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15997 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15998 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15999 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16000 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16001 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16002 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16003 | |
| 16004 | HttpRequestInfo request; |
| 16005 | request.method = "POST"; |
| 16006 | request.url = GURL("http://www.foo.com/"); |
| 16007 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16008 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16009 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16010 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16011 | // Send headers successfully, but get an error while sending the body. |
| 16012 | MockWrite data_writes[] = { |
| 16013 | MockWrite("POST / HTTP/1.1\r\n" |
| 16014 | "Host: www.foo.com\r\n" |
| 16015 | "Connection: keep-alive\r\n" |
| 16016 | "Content-Length: 3\r\n\r\n"), |
| 16017 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16018 | }; |
| 16019 | |
| 16020 | MockRead data_reads[] = { |
| 16021 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16022 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16023 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16024 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16025 | MockRead(SYNCHRONOUS, OK), |
| 16026 | }; |
| 16027 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16028 | arraysize(data_writes)); |
| 16029 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16030 | |
| 16031 | TestCompletionCallback callback; |
| 16032 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16033 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16034 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16035 | |
| 16036 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16037 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16038 | } |
| 16039 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16040 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16041 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16042 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16043 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16044 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16045 | |
| 16046 | HttpRequestInfo request; |
| 16047 | request.method = "POST"; |
| 16048 | request.url = GURL("http://www.foo.com/"); |
| 16049 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16050 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16051 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16052 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16053 | // Send headers successfully, but get an error while sending the body. |
| 16054 | MockWrite data_writes[] = { |
| 16055 | MockWrite("POST / HTTP/1.1\r\n" |
| 16056 | "Host: www.foo.com\r\n" |
| 16057 | "Connection: keep-alive\r\n" |
| 16058 | "Content-Length: 3\r\n\r\n"), |
| 16059 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16060 | }; |
| 16061 | |
| 16062 | MockRead data_reads[] = { |
| 16063 | MockRead("HTTP 0.9 rocks!"), |
| 16064 | MockRead(SYNCHRONOUS, OK), |
| 16065 | }; |
| 16066 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16067 | arraysize(data_writes)); |
| 16068 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16069 | |
| 16070 | TestCompletionCallback callback; |
| 16071 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16072 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16074 | |
| 16075 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16076 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16077 | } |
| 16078 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16079 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16080 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16081 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16082 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16083 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16084 | |
| 16085 | HttpRequestInfo request; |
| 16086 | request.method = "POST"; |
| 16087 | request.url = GURL("http://www.foo.com/"); |
| 16088 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16089 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16090 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16091 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16092 | // Send headers successfully, but get an error while sending the body. |
| 16093 | MockWrite data_writes[] = { |
| 16094 | MockWrite("POST / HTTP/1.1\r\n" |
| 16095 | "Host: www.foo.com\r\n" |
| 16096 | "Connection: keep-alive\r\n" |
| 16097 | "Content-Length: 3\r\n\r\n"), |
| 16098 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16099 | }; |
| 16100 | |
| 16101 | MockRead data_reads[] = { |
| 16102 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16103 | MockRead(SYNCHRONOUS, OK), |
| 16104 | }; |
| 16105 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16106 | arraysize(data_writes)); |
| 16107 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16108 | |
| 16109 | TestCompletionCallback callback; |
| 16110 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16111 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16112 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16113 | |
| 16114 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16115 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16116 | } |
| 16117 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16118 | // Verify that proxy headers are not sent to the destination server when |
| 16119 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16120 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16121 | HttpRequestInfo request; |
| 16122 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16123 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16124 | AddWebSocketHeaders(&request.extra_headers); |
| 16125 | |
| 16126 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16127 | session_deps_.proxy_service = |
| 16128 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16129 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16130 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16131 | |
| 16132 | // Since a proxy is configured, try to establish a tunnel. |
| 16133 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16134 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16135 | "Host: www.example.org:443\r\n" |
| 16136 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16137 | |
| 16138 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16139 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16140 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16141 | "Host: www.example.org:443\r\n" |
| 16142 | "Proxy-Connection: keep-alive\r\n" |
| 16143 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16144 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16145 | MockWrite("GET / HTTP/1.1\r\n" |
| 16146 | "Host: www.example.org\r\n" |
| 16147 | "Connection: Upgrade\r\n" |
| 16148 | "Upgrade: websocket\r\n" |
| 16149 | "Origin: http://www.example.org\r\n" |
| 16150 | "Sec-WebSocket-Version: 13\r\n" |
| 16151 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16152 | }; |
| 16153 | |
| 16154 | // The proxy responds to the connect with a 407, using a persistent |
| 16155 | // connection. |
| 16156 | MockRead data_reads[] = { |
| 16157 | // No credentials. |
| 16158 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16159 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16160 | MockRead("Content-Length: 0\r\n"), |
| 16161 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16162 | |
| 16163 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16164 | |
| 16165 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16166 | MockRead("Upgrade: websocket\r\n"), |
| 16167 | MockRead("Connection: Upgrade\r\n"), |
| 16168 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16169 | }; |
| 16170 | |
| 16171 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16172 | arraysize(data_writes)); |
| 16173 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16174 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16175 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16176 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16177 | auto trans = |
| 16178 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16179 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16180 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16181 | &websocket_stream_create_helper); |
| 16182 | |
| 16183 | { |
| 16184 | TestCompletionCallback callback; |
| 16185 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16186 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16187 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16188 | |
| 16189 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16190 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16191 | } |
| 16192 | |
| 16193 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16194 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16195 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16196 | EXPECT_EQ(407, response->headers->response_code()); |
| 16197 | |
| 16198 | { |
| 16199 | TestCompletionCallback callback; |
| 16200 | |
| 16201 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16202 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16203 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16204 | |
| 16205 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16206 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16207 | } |
| 16208 | |
| 16209 | response = trans->GetResponseInfo(); |
| 16210 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16211 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16212 | |
| 16213 | EXPECT_EQ(101, response->headers->response_code()); |
| 16214 | |
| 16215 | trans.reset(); |
| 16216 | session->CloseAllConnections(); |
| 16217 | } |
| 16218 | |
| 16219 | // Verify that proxy headers are not sent to the destination server when |
| 16220 | // establishing a tunnel for an insecure WebSocket connection. |
| 16221 | // This requires the authentication info to be injected into the auth cache |
| 16222 | // due to crbug.com/395064 |
| 16223 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16224 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16225 | HttpRequestInfo request; |
| 16226 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16227 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16228 | AddWebSocketHeaders(&request.extra_headers); |
| 16229 | |
| 16230 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16231 | session_deps_.proxy_service = |
| 16232 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16233 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16234 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16235 | |
| 16236 | MockWrite data_writes[] = { |
| 16237 | // Try to establish a tunnel for the WebSocket connection, with |
| 16238 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16239 | // they cannot and will not use the same TCP/IP connection as the |
| 16240 | // preflight HTTP request. |
| 16241 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16242 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16243 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16244 | "Proxy-Connection: keep-alive\r\n" |
| 16245 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16246 | |
| 16247 | MockWrite( |
| 16248 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16249 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16250 | "Connection: Upgrade\r\n" |
| 16251 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16252 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16253 | "Sec-WebSocket-Version: 13\r\n" |
| 16254 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16255 | }; |
| 16256 | |
| 16257 | MockRead data_reads[] = { |
| 16258 | // HTTP CONNECT with credentials. |
| 16259 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16260 | |
| 16261 | // WebSocket connection established inside tunnel. |
| 16262 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16263 | MockRead("Upgrade: websocket\r\n"), |
| 16264 | MockRead("Connection: Upgrade\r\n"), |
| 16265 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16266 | }; |
| 16267 | |
| 16268 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16269 | arraysize(data_writes)); |
| 16270 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16271 | |
| 16272 | session->http_auth_cache()->Add( |
| 16273 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16274 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16275 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16276 | auto trans = |
| 16277 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16278 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16279 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16280 | &websocket_stream_create_helper); |
| 16281 | |
| 16282 | TestCompletionCallback callback; |
| 16283 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16284 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16285 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16286 | |
| 16287 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16288 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16289 | |
| 16290 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16291 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16292 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16293 | |
| 16294 | EXPECT_EQ(101, response->headers->response_code()); |
| 16295 | |
| 16296 | trans.reset(); |
| 16297 | session->CloseAllConnections(); |
| 16298 | } |
| 16299 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16300 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16301 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16302 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16303 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16304 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16305 | |
| 16306 | HttpRequestInfo request; |
| 16307 | request.method = "POST"; |
| 16308 | request.url = GURL("http://www.foo.com/"); |
| 16309 | request.upload_data_stream = &upload_data_stream; |
| 16310 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16311 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16312 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16313 | MockWrite data_writes[] = { |
| 16314 | MockWrite("POST / HTTP/1.1\r\n" |
| 16315 | "Host: www.foo.com\r\n" |
| 16316 | "Connection: keep-alive\r\n" |
| 16317 | "Content-Length: 3\r\n\r\n"), |
| 16318 | MockWrite("foo"), |
| 16319 | }; |
| 16320 | |
| 16321 | MockRead data_reads[] = { |
| 16322 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16323 | MockRead(SYNCHRONOUS, OK), |
| 16324 | }; |
| 16325 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16326 | arraysize(data_writes)); |
| 16327 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16328 | |
| 16329 | TestCompletionCallback callback; |
| 16330 | |
| 16331 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16332 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16333 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16334 | |
| 16335 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16336 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16337 | |
| 16338 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16339 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16340 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16341 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16342 | } |
| 16343 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16344 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16345 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16346 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16347 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16348 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16349 | |
| 16350 | HttpRequestInfo request; |
| 16351 | request.method = "POST"; |
| 16352 | request.url = GURL("http://www.foo.com/"); |
| 16353 | request.upload_data_stream = &upload_data_stream; |
| 16354 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16355 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16356 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16357 | MockWrite data_writes[] = { |
| 16358 | MockWrite("POST / HTTP/1.1\r\n" |
| 16359 | "Host: www.foo.com\r\n" |
| 16360 | "Connection: keep-alive\r\n" |
| 16361 | "Content-Length: 3\r\n\r\n"), |
| 16362 | MockWrite("foo"), |
| 16363 | }; |
| 16364 | |
| 16365 | MockRead data_reads[] = { |
| 16366 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16367 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16368 | MockRead(SYNCHRONOUS, OK), |
| 16369 | }; |
| 16370 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16371 | arraysize(data_writes)); |
| 16372 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16373 | |
| 16374 | TestCompletionCallback callback; |
| 16375 | |
| 16376 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16377 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16378 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16379 | |
| 16380 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16381 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16382 | |
| 16383 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16384 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16385 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16386 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16387 | } |
| 16388 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16389 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16390 | ChunkedUploadDataStream upload_data_stream(0); |
| 16391 | |
| 16392 | HttpRequestInfo request; |
| 16393 | request.method = "POST"; |
| 16394 | request.url = GURL("http://www.foo.com/"); |
| 16395 | request.upload_data_stream = &upload_data_stream; |
| 16396 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16397 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16398 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16399 | // Send headers successfully, but get an error while sending the body. |
| 16400 | MockWrite data_writes[] = { |
| 16401 | MockWrite("POST / HTTP/1.1\r\n" |
| 16402 | "Host: www.foo.com\r\n" |
| 16403 | "Connection: keep-alive\r\n" |
| 16404 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16405 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16406 | }; |
| 16407 | |
| 16408 | MockRead data_reads[] = { |
| 16409 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16410 | MockRead(SYNCHRONOUS, OK), |
| 16411 | }; |
| 16412 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16413 | arraysize(data_writes)); |
| 16414 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16415 | |
| 16416 | TestCompletionCallback callback; |
| 16417 | |
| 16418 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16419 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16420 | |
| 16421 | base::RunLoop().RunUntilIdle(); |
| 16422 | upload_data_stream.AppendData("f", 1, false); |
| 16423 | |
| 16424 | base::RunLoop().RunUntilIdle(); |
| 16425 | upload_data_stream.AppendData("oo", 2, true); |
| 16426 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16427 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16428 | |
| 16429 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16430 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16431 | |
| 16432 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16433 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16434 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16435 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16436 | } |
| 16437 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16438 | // Confirm that transactions whose throttle is created in (and stays in) |
| 16439 | // the unthrottled state are not blocked. |
| 16440 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 16441 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16442 | std::unique_ptr<HttpNetworkSession> session( |
| 16443 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16444 | |
| 16445 | // Send a simple request and make sure it goes through. |
| 16446 | HttpRequestInfo request; |
| 16447 | request.method = "GET"; |
| 16448 | request.url = GURL("http://www.example.org/"); |
| 16449 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16450 | auto trans = |
| 16451 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16452 | |
| 16453 | MockWrite data_writes[] = { |
| 16454 | MockWrite("GET / HTTP/1.1\r\n" |
| 16455 | "Host: www.example.org\r\n" |
| 16456 | "Connection: keep-alive\r\n\r\n"), |
| 16457 | }; |
| 16458 | MockRead data_reads[] = { |
| 16459 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16460 | MockRead(SYNCHRONOUS, OK), |
| 16461 | }; |
| 16462 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16463 | arraysize(data_writes)); |
| 16464 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16465 | |
| 16466 | TestCompletionCallback callback; |
| 16467 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16468 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16469 | } |
| 16470 | |
| 16471 | // Confirm requests can be blocked by a throttler, and are resumed |
| 16472 | // when the throttle is unblocked. |
| 16473 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 16474 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16475 | std::unique_ptr<HttpNetworkSession> session( |
| 16476 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16477 | |
| 16478 | // Send a simple request and make sure it goes through. |
| 16479 | HttpRequestInfo request; |
| 16480 | request.method = "GET"; |
| 16481 | request.url = GURL("http://www.example.org/"); |
| 16482 | |
| 16483 | MockWrite data_writes[] = { |
| 16484 | MockWrite("GET / HTTP/1.1\r\n" |
| 16485 | "Host: www.example.org\r\n" |
| 16486 | "Connection: keep-alive\r\n\r\n"), |
| 16487 | }; |
| 16488 | MockRead data_reads[] = { |
| 16489 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16490 | MockRead(SYNCHRONOUS, OK), |
| 16491 | }; |
| 16492 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16493 | arraysize(data_writes)); |
| 16494 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16495 | |
| 16496 | // Start a request that will be throttled at start; confirm it |
| 16497 | // doesn't complete. |
| 16498 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16499 | auto trans = |
| 16500 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16501 | |
| 16502 | TestCompletionCallback callback; |
| 16503 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16504 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16505 | |
| 16506 | base::RunLoop().RunUntilIdle(); |
| 16507 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16508 | EXPECT_FALSE(callback.have_result()); |
| 16509 | |
| 16510 | // Confirm the request goes on to complete when unthrottled. |
| 16511 | throttler->UnthrottleAllRequests(); |
| 16512 | base::RunLoop().RunUntilIdle(); |
| 16513 | ASSERT_TRUE(callback.have_result()); |
| 16514 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16515 | } |
| 16516 | |
| 16517 | // Destroy a request while it's throttled. |
| 16518 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 16519 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16520 | std::unique_ptr<HttpNetworkSession> session( |
| 16521 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16522 | |
| 16523 | // Send a simple request and make sure it goes through. |
| 16524 | HttpRequestInfo request; |
| 16525 | request.method = "GET"; |
| 16526 | request.url = GURL("http://www.example.org/"); |
| 16527 | |
| 16528 | MockWrite data_writes[] = { |
| 16529 | MockWrite("GET / HTTP/1.1\r\n" |
| 16530 | "Host: www.example.org\r\n" |
| 16531 | "Connection: keep-alive\r\n\r\n"), |
| 16532 | }; |
| 16533 | MockRead data_reads[] = { |
| 16534 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16535 | MockRead(SYNCHRONOUS, OK), |
| 16536 | }; |
| 16537 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16538 | arraysize(data_writes)); |
| 16539 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16540 | |
| 16541 | // Start a request that will be throttled at start; confirm it |
| 16542 | // doesn't complete. |
| 16543 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16544 | auto trans = |
| 16545 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16546 | |
| 16547 | TestCompletionCallback callback; |
| 16548 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16549 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16550 | |
| 16551 | base::RunLoop().RunUntilIdle(); |
| 16552 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16553 | EXPECT_FALSE(callback.have_result()); |
| 16554 | |
| 16555 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 16556 | trans.reset(); |
| 16557 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 16558 | } |
| 16559 | |
| 16560 | // Confirm the throttler receives SetPriority calls. |
| 16561 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 16562 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16563 | std::unique_ptr<HttpNetworkSession> session( |
| 16564 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16565 | |
| 16566 | // Send a simple request and make sure it goes through. |
| 16567 | HttpRequestInfo request; |
| 16568 | request.method = "GET"; |
| 16569 | request.url = GURL("http://www.example.org/"); |
| 16570 | |
| 16571 | MockWrite data_writes[] = { |
| 16572 | MockWrite("GET / HTTP/1.1\r\n" |
| 16573 | "Host: www.example.org\r\n" |
| 16574 | "Connection: keep-alive\r\n\r\n"), |
| 16575 | }; |
| 16576 | MockRead data_reads[] = { |
| 16577 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16578 | MockRead(SYNCHRONOUS, OK), |
| 16579 | }; |
| 16580 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16581 | arraysize(data_writes)); |
| 16582 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16583 | |
| 16584 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16585 | auto trans = base::MakeUnique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16586 | // Start the transaction to associate a throttle with it. |
| 16587 | TestCompletionCallback callback; |
| 16588 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16589 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16590 | |
| 16591 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 16592 | trans->SetPriority(LOW); |
| 16593 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 16594 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 16595 | |
| 16596 | throttler->UnthrottleAllRequests(); |
| 16597 | base::RunLoop().RunUntilIdle(); |
| 16598 | ASSERT_TRUE(callback.have_result()); |
| 16599 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16600 | } |
| 16601 | |
| 16602 | // Confirm that unthrottling from a SetPriority call by the |
| 16603 | // throttler works properly. |
| 16604 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 16605 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16606 | std::unique_ptr<HttpNetworkSession> session( |
| 16607 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16608 | |
| 16609 | // Send a simple request and make sure it goes through. |
| 16610 | HttpRequestInfo request; |
| 16611 | request.method = "GET"; |
| 16612 | request.url = GURL("http://www.example.org/"); |
| 16613 | |
| 16614 | MockWrite data_writes[] = { |
| 16615 | MockWrite("GET / HTTP/1.1\r\n" |
| 16616 | "Host: www.example.org\r\n" |
| 16617 | "Connection: keep-alive\r\n\r\n"), |
| 16618 | }; |
| 16619 | MockRead data_reads[] = { |
| 16620 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16621 | MockRead(SYNCHRONOUS, OK), |
| 16622 | }; |
| 16623 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16624 | arraysize(data_writes)); |
| 16625 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16626 | |
| 16627 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16628 | data_writes, arraysize(data_writes)); |
| 16629 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16630 | |
| 16631 | // Start a request that will be throttled at start; confirm it |
| 16632 | // doesn't complete. |
| 16633 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16634 | auto trans = |
| 16635 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16636 | |
| 16637 | TestCompletionCallback callback; |
| 16638 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16639 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16640 | |
| 16641 | base::RunLoop().RunUntilIdle(); |
| 16642 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16643 | EXPECT_FALSE(callback.have_result()); |
| 16644 | |
| 16645 | // Create a new request, call SetPriority on it to unthrottle, |
| 16646 | // and make sure that allows the original request to complete. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16647 | auto trans1 = base::MakeUnique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16648 | throttler->set_priority_change_closure( |
| 16649 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 16650 | base::Unretained(throttler))); |
| 16651 | |
| 16652 | // Start the transaction to associate a throttle with it. |
| 16653 | TestCompletionCallback callback1; |
| 16654 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 16655 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16656 | |
| 16657 | trans1->SetPriority(IDLE); |
| 16658 | |
| 16659 | base::RunLoop().RunUntilIdle(); |
| 16660 | ASSERT_TRUE(callback.have_result()); |
| 16661 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16662 | ASSERT_TRUE(callback1.have_result()); |
| 16663 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 16664 | } |
| 16665 | |
| 16666 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16667 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16668 | |
| 16669 | // Confirm that destroying a transaction from a SetPriority call by the |
| 16670 | // throttler works properly. |
| 16671 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 16672 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16673 | std::unique_ptr<HttpNetworkSession> session( |
| 16674 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16675 | |
| 16676 | // Send a simple request and make sure it goes through. |
| 16677 | HttpRequestInfo request; |
| 16678 | request.method = "GET"; |
| 16679 | request.url = GURL("http://www.example.org/"); |
| 16680 | |
| 16681 | MockWrite data_writes[] = { |
| 16682 | MockWrite("GET / HTTP/1.1\r\n" |
| 16683 | "Host: www.example.org\r\n" |
| 16684 | "Connection: keep-alive\r\n\r\n"), |
| 16685 | }; |
| 16686 | MockRead data_reads[] = { |
| 16687 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16688 | MockRead(SYNCHRONOUS, OK), |
| 16689 | }; |
| 16690 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16691 | arraysize(data_writes)); |
| 16692 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16693 | |
| 16694 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16695 | data_writes, arraysize(data_writes)); |
| 16696 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16697 | |
| 16698 | // Start a request that will be throttled at start; confirm it |
| 16699 | // doesn't complete. |
| 16700 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16701 | auto trans = |
| 16702 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16703 | |
| 16704 | TestCompletionCallback callback; |
| 16705 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16706 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16707 | |
| 16708 | base::RunLoop().RunUntilIdle(); |
| 16709 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16710 | EXPECT_FALSE(callback.have_result()); |
| 16711 | |
| 16712 | // Arrange for the set priority call on the above transaction to delete |
| 16713 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16714 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16715 | throttler->set_priority_change_closure( |
| 16716 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 16717 | |
| 16718 | // Call it and check results (partially a "doesn't crash" test). |
| 16719 | trans_ptr->SetPriority(IDLE); |
| 16720 | trans_ptr = nullptr; // No longer a valid pointer. |
| 16721 | |
| 16722 | base::RunLoop().RunUntilIdle(); |
| 16723 | ASSERT_FALSE(callback.have_result()); |
| 16724 | } |
| 16725 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16726 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16727 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16728 | const std::string https_url = "https://www.example.com"; |
| 16729 | HttpRequestInfo request; |
| 16730 | request.url = GURL(https_url); |
| 16731 | request.method = "GET"; |
| 16732 | |
| 16733 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16734 | ssl.token_binding_negotiated = true; |
| 16735 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16736 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16737 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16738 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16739 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16740 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16741 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16742 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 16743 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 16744 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16745 | session_deps_.channel_id_service = |
| 16746 | base::MakeUnique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16747 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16748 | |
| 16749 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16750 | TestCompletionCallback callback; |
| 16751 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16752 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 16753 | |
| 16754 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16755 | |
| 16756 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16757 | HttpRequestHeaders headers; |
| 16758 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16759 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16760 | } |
| 16761 | #endif // !defined(OS_IOS) |
| 16762 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16763 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 16764 | const std::string& accept_encoding, |
| 16765 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16766 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16767 | bool should_match) { |
| 16768 | HttpRequestInfo request; |
| 16769 | request.method = "GET"; |
| 16770 | request.url = GURL("http://www.foo.com/"); |
| 16771 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 16772 | accept_encoding); |
| 16773 | |
| 16774 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 16775 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16776 | // Send headers successfully, but get an error while sending the body. |
| 16777 | MockWrite data_writes[] = { |
| 16778 | MockWrite("GET / HTTP/1.1\r\n" |
| 16779 | "Host: www.foo.com\r\n" |
| 16780 | "Connection: keep-alive\r\n" |
| 16781 | "Accept-Encoding: "), |
| 16782 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 16783 | }; |
| 16784 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16785 | std::string response_code = "200 OK"; |
| 16786 | std::string extra; |
| 16787 | if (!location.empty()) { |
| 16788 | response_code = "301 Redirect\r\nLocation: "; |
| 16789 | response_code.append(location); |
| 16790 | } |
| 16791 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16792 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16793 | MockRead("HTTP/1.0 "), |
| 16794 | MockRead(response_code.data()), |
| 16795 | MockRead("\r\nContent-Encoding: "), |
| 16796 | MockRead(content_encoding.data()), |
| 16797 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16798 | MockRead(SYNCHRONOUS, OK), |
| 16799 | }; |
| 16800 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16801 | arraysize(data_writes)); |
| 16802 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 16803 | |
| 16804 | TestCompletionCallback callback; |
| 16805 | |
| 16806 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16807 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16808 | |
| 16809 | rv = callback.WaitForResult(); |
| 16810 | if (should_match) { |
| 16811 | EXPECT_THAT(rv, IsOk()); |
| 16812 | } else { |
| 16813 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 16814 | } |
| 16815 | } |
| 16816 | |
| 16817 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16818 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16819 | } |
| 16820 | |
| 16821 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16822 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 16823 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16824 | } |
| 16825 | |
| 16826 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 16827 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16828 | "", false); |
| 16829 | } |
| 16830 | |
| 16831 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 16832 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 16833 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16834 | } |
| 16835 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 16836 | } // namespace net |