[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 9 | #include <stdint.h> |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11 | #include <limits> |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 12 | #include <set> |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 13 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14 | #include <utility> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 15 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 16 | |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 17 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 18 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 19 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 20 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 21 | #include "base/logging.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 22 | #include "base/macros.h" |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 23 | #include "base/memory/ptr_util.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 24 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 25 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 26 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 27 | #include "base/strings/utf_string_conversions.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 28 | #include "base/test/scoped_task_environment.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 29 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 30 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 31 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 32 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 33 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 34 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 35 | #include "net/base/load_timing_info.h" |
| 36 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 37 | #include "net/base/net_errors.h" |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 38 | #include "net/base/network_throttle_manager.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 39 | #include "net/base/proxy_delegate.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 40 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 41 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 42 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 43 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 44 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 45 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 46 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 47 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 48 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 49 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 50 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 51 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 52 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 53 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 54 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 55 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 56 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 57 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 58 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 59 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 60 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 61 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 62 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 63 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 64 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 65 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 66 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 67 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 68 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 69 | #include "net/log/test_net_log_entry.h" |
| 70 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 71 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 72 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 73 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 74 | #include "net/proxy/proxy_resolver.h" |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 75 | #include "net/proxy/proxy_resolver_factory.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 76 | #include "net/proxy/proxy_server.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 77 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 78 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 79 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 80 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 81 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 82 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 83 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 84 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 85 | #include "net/socket/socket_test_util.h" |
| 86 | #include "net/socket/ssl_client_socket.h" |
bnc | 8f8f7d30 | 2017-04-24 18:08:06 | [diff] [blame] | 87 | #include "net/spdy/chromium/spdy_session.h" |
| 88 | #include "net/spdy/chromium/spdy_session_pool.h" |
| 89 | #include "net/spdy/chromium/spdy_test_util_common.h" |
| 90 | #include "net/spdy/core/spdy_framer.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 91 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 92 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 93 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 94 | #include "net/ssl/ssl_config_service_defaults.h" |
| 95 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 96 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 97 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 98 | #include "net/test/gtest_util.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 99 | #include "net/test/net_test_suite.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 100 | #include "net/test/test_data_directory.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 101 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 102 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 103 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 104 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 105 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 106 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 107 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 108 | #if defined(NTLM_PORTABLE) |
| 109 | #include "base/base64.h" |
| 110 | #include "net/ntlm/ntlm_test_data.h" |
| 111 | #endif |
| 112 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 113 | using net::test::IsError; |
| 114 | using net::test::IsOk; |
| 115 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 116 | using base::ASCIIToUTF16; |
| 117 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 118 | //----------------------------------------------------------------------------- |
| 119 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 120 | namespace net { |
| 121 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 122 | namespace { |
| 123 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 124 | class TestNetworkStreamThrottler : public NetworkThrottleManager { |
| 125 | public: |
| 126 | TestNetworkStreamThrottler() |
| 127 | : throttle_new_requests_(false), |
| 128 | num_set_priority_calls_(0), |
| 129 | last_priority_set_(IDLE) {} |
| 130 | |
| 131 | ~TestNetworkStreamThrottler() override { |
| 132 | EXPECT_TRUE(outstanding_throttles_.empty()); |
| 133 | } |
| 134 | |
| 135 | // NetworkThrottleManager |
| 136 | std::unique_ptr<Throttle> CreateThrottle(ThrottleDelegate* delegate, |
| 137 | RequestPriority priority, |
| 138 | bool ignore_limits) override { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 139 | auto test_throttle = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 140 | std::make_unique<TestThrottle>(throttle_new_requests_, delegate, this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 141 | outstanding_throttles_.insert(test_throttle.get()); |
| 142 | return std::move(test_throttle); |
| 143 | } |
| 144 | |
| 145 | void UnthrottleAllRequests() { |
| 146 | std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
vmpstr | 6d9996c8 | 2017-02-23 00:43:25 | [diff] [blame] | 147 | for (auto* throttle : outstanding_throttles_copy) { |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 148 | if (throttle->IsBlocked()) |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 149 | throttle->Unthrottle(); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void set_throttle_new_requests(bool throttle_new_requests) { |
| 154 | throttle_new_requests_ = throttle_new_requests; |
| 155 | } |
| 156 | |
| 157 | // Includes both throttled and unthrottled throttles. |
| 158 | size_t num_outstanding_requests() const { |
| 159 | return outstanding_throttles_.size(); |
| 160 | } |
| 161 | |
| 162 | int num_set_priority_calls() const { return num_set_priority_calls_; } |
| 163 | RequestPriority last_priority_set() const { return last_priority_set_; } |
| 164 | void set_priority_change_closure( |
| 165 | const base::Closure& priority_change_closure) { |
| 166 | priority_change_closure_ = priority_change_closure; |
| 167 | } |
| 168 | |
| 169 | private: |
| 170 | class TestThrottle : public NetworkThrottleManager::Throttle { |
| 171 | public: |
| 172 | ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
| 173 | |
| 174 | // Throttle |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 175 | bool IsBlocked() const override { return throttled_; } |
| 176 | RequestPriority Priority() const override { |
| 177 | NOTREACHED(); |
| 178 | return IDLE; |
| 179 | } |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 180 | void SetPriority(RequestPriority priority) override { |
| 181 | throttler_->SetPriorityCalled(priority); |
| 182 | } |
| 183 | |
| 184 | TestThrottle(bool throttled, |
| 185 | ThrottleDelegate* delegate, |
| 186 | TestNetworkStreamThrottler* throttler) |
| 187 | : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 188 | |
| 189 | void Unthrottle() { |
| 190 | EXPECT_TRUE(throttled_); |
| 191 | |
| 192 | throttled_ = false; |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 193 | delegate_->OnThrottleUnblocked(this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | bool throttled_; |
| 197 | ThrottleDelegate* delegate_; |
| 198 | TestNetworkStreamThrottler* throttler_; |
| 199 | }; |
| 200 | |
| 201 | void OnThrottleDestroyed(TestThrottle* throttle) { |
| 202 | EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 203 | outstanding_throttles_.erase(throttle); |
| 204 | } |
| 205 | |
| 206 | void SetPriorityCalled(RequestPriority priority) { |
| 207 | ++num_set_priority_calls_; |
| 208 | last_priority_set_ = priority; |
| 209 | if (!priority_change_closure_.is_null()) |
| 210 | priority_change_closure_.Run(); |
| 211 | } |
| 212 | |
| 213 | // Includes both throttled and unthrottled throttles. |
| 214 | std::set<TestThrottle*> outstanding_throttles_; |
| 215 | bool throttle_new_requests_; |
| 216 | int num_set_priority_calls_; |
| 217 | RequestPriority last_priority_set_; |
| 218 | base::Closure priority_change_closure_; |
| 219 | |
| 220 | DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler); |
| 221 | }; |
| 222 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 223 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 224 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 225 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 226 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 227 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 228 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 229 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 230 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 231 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 232 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 233 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 234 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 235 | const char kAlternativeServiceHttpHeader[] = |
| 236 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 237 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 238 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 239 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 240 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 241 | } |
| 242 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 243 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 244 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 245 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 246 | } |
| 247 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 248 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 249 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 250 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 251 | } |
| 252 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 253 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 254 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 255 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 256 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 257 | if (!params) |
| 258 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 259 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 260 | if (!params->GetList("headers", &header_list)) |
| 261 | return false; |
| 262 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 263 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 264 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 265 | return true; |
| 266 | } |
| 267 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 268 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 269 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 270 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 271 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 272 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 273 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 274 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 275 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 276 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 277 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 278 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 279 | |
| 280 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 281 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 282 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 283 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 284 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 285 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 286 | } |
| 287 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 288 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 289 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 290 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 291 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 292 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 293 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 294 | |
| 295 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 296 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 297 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 298 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 299 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 300 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 301 | load_timing_info.send_start); |
| 302 | |
| 303 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 304 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 305 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 306 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 307 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 308 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 312 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 313 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 314 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 315 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 316 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 317 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 318 | |
| 319 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 320 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 321 | load_timing_info.proxy_resolve_end); |
| 322 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 323 | load_timing_info.send_start); |
| 324 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 325 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 326 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 327 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 328 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 329 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 333 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 334 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 335 | int connect_timing_flags) { |
| 336 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 337 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 338 | |
| 339 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 340 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 341 | load_timing_info.proxy_resolve_end); |
| 342 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 343 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 344 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 345 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 346 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 347 | load_timing_info.send_start); |
| 348 | |
| 349 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 350 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 351 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 352 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 353 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 354 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 355 | } |
| 356 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 357 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 358 | headers->SetHeader("Connection", "Upgrade"); |
| 359 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 360 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 361 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 362 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 363 | } |
| 364 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 365 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 366 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 367 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 368 | } |
| 369 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 370 | // Note that the pointer written into |*throttler| will only be valid |
| 371 | // for the lifetime of the returned HttpNetworkSession. |
| 372 | std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler( |
| 373 | SpdySessionDependencies* session_deps, |
| 374 | TestNetworkStreamThrottler** throttler) { |
| 375 | std::unique_ptr<HttpNetworkSession> session( |
| 376 | SpdySessionDependencies::SpdyCreateSession(session_deps)); |
| 377 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 378 | auto owned_throttler = std::make_unique<TestNetworkStreamThrottler>(); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 379 | *throttler = owned_throttler.get(); |
| 380 | |
| 381 | HttpNetworkSessionPeer peer(session.get()); |
| 382 | peer.SetNetworkStreamThrottler(std::move(owned_throttler)); |
| 383 | |
| 384 | return session; |
| 385 | } |
| 386 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 387 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 388 | public: |
| 389 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 390 | |
| 391 | // ProxyResolverFactory override. |
| 392 | int CreateProxyResolver( |
| 393 | const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 394 | std::unique_ptr<ProxyResolver>* result, |
| 395 | const CompletionCallback& callback, |
| 396 | std::unique_ptr<Request>* request) override { |
| 397 | return ERR_PAC_SCRIPT_FAILED; |
| 398 | } |
| 399 | }; |
| 400 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 401 | } // namespace |
| 402 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 403 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 404 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 405 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 406 | // Important to restore the per-pool limit first, since the pool limit must |
| 407 | // always be greater than group limit, and the tests reduce both limits. |
| 408 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 409 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 410 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 411 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 412 | } |
| 413 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 414 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 415 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 416 | : ssl_(ASYNC, OK), |
| 417 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 418 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 419 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 420 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 421 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 422 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 423 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 424 | struct SimpleGetHelperResult { |
| 425 | int rv; |
| 426 | std::string status_line; |
| 427 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 428 | int64_t total_received_bytes; |
| 429 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 430 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 431 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 432 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 433 | }; |
| 434 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 435 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 436 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 437 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 438 | } |
| 439 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 440 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 441 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 442 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 443 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 444 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 445 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 446 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 447 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 448 | } |
| 449 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 450 | // Either |write_failure| specifies a write failure or |read_failure| |
| 451 | // specifies a read failure when using a reused socket. In either case, the |
| 452 | // failure should cause the network transaction to resend the request, and the |
| 453 | // other argument should be NULL. |
| 454 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 455 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 456 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 457 | // Either |write_failure| specifies a write failure or |read_failure| |
| 458 | // specifies a read failure when using a reused socket. In either case, the |
| 459 | // failure should cause the network transaction to resend the request, and the |
| 460 | // other argument should be NULL. |
| 461 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 462 | const MockRead* read_failure, |
| 463 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 464 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 465 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 466 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 467 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 468 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 469 | HttpRequestInfo request; |
| 470 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 471 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 472 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 473 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 474 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 475 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 476 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 477 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 478 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 479 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 480 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 482 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 483 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 484 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 485 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 487 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 488 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 489 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 490 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 491 | |
| 492 | // Even in the failure cases that use this function, connections are always |
| 493 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 494 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 495 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 496 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 497 | if (out.rv != OK) |
| 498 | return out; |
| 499 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 500 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 501 | // Can't use ASSERT_* inside helper functions like this, so |
| 502 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 503 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 504 | out.rv = ERR_UNEXPECTED; |
| 505 | return out; |
| 506 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 507 | out.status_line = response->headers->GetStatusLine(); |
| 508 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 509 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 510 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 511 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 512 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 513 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 514 | EXPECT_EQ(got_endpoint, |
| 515 | out.remote_endpoint_after_start.address().size() > 0); |
| 516 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 517 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 518 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 519 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 520 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 521 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 522 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 523 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 524 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 525 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 526 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 527 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 528 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 529 | std::string line; |
| 530 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 531 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 532 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 533 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 534 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 535 | std::string value; |
| 536 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 537 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 538 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 539 | EXPECT_EQ("keep-alive", value); |
| 540 | |
| 541 | std::string response_headers; |
| 542 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 543 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 544 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 545 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 546 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 547 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 548 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 549 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 550 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 551 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 552 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 553 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 554 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 555 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 556 | MockWrite data_writes[] = { |
| 557 | MockWrite("GET / HTTP/1.1\r\n" |
| 558 | "Host: www.example.org\r\n" |
| 559 | "Connection: keep-alive\r\n\r\n"), |
| 560 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 561 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 562 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 563 | arraysize(data_writes)); |
| 564 | StaticSocketDataProvider* data[] = {&reads}; |
| 565 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 566 | |
| 567 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 568 | out.total_sent_bytes); |
| 569 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 570 | } |
| 571 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 572 | void AddSSLSocketData() { |
| 573 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 574 | ssl_.ssl_info.cert = |
| 575 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 576 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 577 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 578 | } |
| 579 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 580 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 581 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 582 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 583 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 584 | |
| 585 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 586 | |
| 587 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 588 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 589 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 590 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 591 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 592 | |
| 593 | // Original socket limits. Some tests set these. Safest to always restore |
| 594 | // them once each test has been run. |
| 595 | int old_max_group_sockets_; |
| 596 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 597 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 598 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 599 | namespace { |
| 600 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 601 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 602 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 603 | BeforeHeadersSentHandler() |
| 604 | : observed_before_headers_sent_with_proxy_(false), |
| 605 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 606 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 607 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 608 | HttpRequestHeaders* request_headers) { |
| 609 | observed_before_headers_sent_ = true; |
| 610 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 611 | !proxy_info.is_quic()) { |
| 612 | return; |
| 613 | } |
| 614 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 615 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 616 | } |
| 617 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 618 | bool observed_before_headers_sent_with_proxy() const { |
| 619 | return observed_before_headers_sent_with_proxy_; |
| 620 | } |
| 621 | |
| 622 | bool observed_before_headers_sent() const { |
| 623 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | std::string observed_proxy_server_uri() const { |
| 627 | return observed_proxy_server_uri_; |
| 628 | } |
| 629 | |
| 630 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 631 | bool observed_before_headers_sent_with_proxy_; |
| 632 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 633 | std::string observed_proxy_server_uri_; |
| 634 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 635 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 636 | }; |
| 637 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 638 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 639 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 640 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 641 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 642 | const int sizeof_row = strlen(row); |
| 643 | const int num_rows = static_cast<int>( |
| 644 | ceil(static_cast<float>(size) / sizeof_row)); |
| 645 | const int sizeof_data = num_rows * sizeof_row; |
| 646 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 647 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 648 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 649 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 650 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 651 | } |
| 652 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 653 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 654 | uint64_t MockGetMSTime() { |
| 655 | // Tue, 23 May 2017 20:13:07 +0000 |
| 656 | return 131400439870000000; |
| 657 | } |
| 658 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 659 | // Alternative functions that eliminate randomness and dependency on the local |
| 660 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 661 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 662 | // This is set to 0xaa because the client challenge for testing in |
| 663 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 664 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 665 | } |
| 666 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 667 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 668 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 669 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 670 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 671 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 672 | template<typename ParentPool> |
| 673 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 674 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 675 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 676 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 677 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 678 | const std::string last_group_name_received() const { |
| 679 | return last_group_name_; |
| 680 | } |
| 681 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 682 | bool socket_requested() const { return socket_requested_; } |
| 683 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 684 | int RequestSocket(const std::string& group_name, |
| 685 | const void* socket_params, |
| 686 | RequestPriority priority, |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 687 | const SocketTag& socket_tag, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 688 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 689 | ClientSocketHandle* handle, |
| 690 | const CompletionCallback& callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 691 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 692 | last_group_name_ = group_name; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 693 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 694 | return ERR_IO_PENDING; |
| 695 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 696 | void CancelRequest(const std::string& group_name, |
| 697 | ClientSocketHandle* handle) override {} |
| 698 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 699 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 700 | int id) override {} |
| 701 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 702 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 703 | int IdleSocketCount() const override { return 0; } |
| 704 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 705 | return 0; |
| 706 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 707 | LoadState GetLoadState(const std::string& group_name, |
| 708 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 709 | return LOAD_STATE_IDLE; |
| 710 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 711 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 712 | return base::TimeDelta(); |
| 713 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 714 | |
| 715 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 716 | std::string last_group_name_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 717 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 718 | }; |
| 719 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 720 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 721 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 722 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 723 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 724 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 725 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 726 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 727 | CaptureGroupNameSSLSocketPool; |
| 728 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 729 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 730 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 731 | HostResolver* host_resolver, |
| 732 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 733 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 734 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 735 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 736 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 737 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 738 | CertVerifier* /* cert_verifier */) |
tbansal | 16196a1e | 2017-06-09 01:50:09 | [diff] [blame] | 739 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 740 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 741 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 742 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 743 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 744 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 745 | : SSLClientSocketPool(0, |
| 746 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 747 | cert_verifier, |
| 748 | NULL, |
| 749 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 750 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 751 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 752 | std::string(), |
| 753 | NULL, |
| 754 | NULL, |
| 755 | NULL, |
| 756 | NULL, |
| 757 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 758 | NULL) { |
| 759 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 760 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 761 | //----------------------------------------------------------------------------- |
| 762 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 763 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 764 | // configured for common cases. |
| 765 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 766 | if (!auth_challenge) |
| 767 | return false; |
| 768 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 769 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 770 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 771 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 772 | return true; |
| 773 | } |
| 774 | |
| 775 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 776 | if (!auth_challenge) |
| 777 | return false; |
| 778 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 779 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 780 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 781 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 782 | return true; |
| 783 | } |
| 784 | |
| 785 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 786 | if (!auth_challenge) |
| 787 | return false; |
| 788 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 789 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 790 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 791 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 792 | return true; |
| 793 | } |
| 794 | |
| 795 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 796 | if (!auth_challenge) |
| 797 | return false; |
| 798 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 799 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 800 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 801 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 802 | return true; |
| 803 | } |
| 804 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 805 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 806 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 807 | if (!auth_challenge) |
| 808 | return false; |
| 809 | EXPECT_FALSE(auth_challenge->is_proxy); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 810 | EXPECT_EQ("https://172.22.68.17", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 811 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 812 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 813 | return true; |
| 814 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 815 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 816 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 817 | } // namespace |
| 818 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 819 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 820 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 821 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 822 | } |
| 823 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 824 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 825 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 826 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 827 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 828 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 829 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 830 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 831 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 832 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 833 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 834 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 835 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 836 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 837 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 838 | |
| 839 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 843 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 844 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 845 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 846 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 847 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 848 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 849 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 850 | EXPECT_THAT(out.rv, IsOk()); |
| 851 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 852 | EXPECT_EQ("hello world", out.response_data); |
| 853 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 854 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 855 | } |
| 856 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 857 | // Response with no status line, and a weird port. Should fail by default. |
| 858 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 859 | MockRead data_reads[] = { |
| 860 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 861 | }; |
| 862 | |
| 863 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 864 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 865 | |
| 866 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 867 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 868 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 869 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 870 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 871 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 872 | request.method = "GET"; |
| 873 | request.url = GURL("http://www.example.com:2000/"); |
| 874 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 875 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 876 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 877 | } |
| 878 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 879 | // Tests that request info can be destroyed after the headers phase is complete. |
| 880 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 881 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 882 | auto trans = |
| 883 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 884 | |
| 885 | MockRead data_reads[] = { |
| 886 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 887 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 888 | }; |
| 889 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 890 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 891 | |
| 892 | TestCompletionCallback callback; |
| 893 | |
| 894 | { |
| 895 | auto request = std::make_unique<HttpRequestInfo>(); |
| 896 | request->method = "GET"; |
| 897 | request->url = GURL("http://www.example.org/"); |
| 898 | |
| 899 | int rv = |
| 900 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 901 | |
| 902 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 903 | } // Let request info be destroyed. |
| 904 | |
| 905 | trans.reset(); |
| 906 | } |
| 907 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 908 | // Response with no status line, and a weird port. Option to allow weird ports |
| 909 | // enabled. |
| 910 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 911 | MockRead data_reads[] = { |
| 912 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 913 | }; |
| 914 | |
| 915 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 916 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 917 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 918 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 919 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 920 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 921 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 922 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 923 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 924 | request.method = "GET"; |
| 925 | request.url = GURL("http://www.example.com:2000/"); |
| 926 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 927 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 928 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 929 | |
| 930 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 931 | ASSERT_TRUE(info->headers); |
| 932 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 933 | |
| 934 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 935 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 936 | } |
| 937 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 938 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 939 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 940 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 941 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 942 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 943 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 944 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 945 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 946 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 947 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 948 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 949 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 950 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 954 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 955 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 956 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 957 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 958 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 959 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 960 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 961 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 962 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 963 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 964 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 965 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 969 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 970 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 971 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 972 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 973 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 974 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 975 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 976 | EXPECT_THAT(out.rv, IsOk()); |
| 977 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 978 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 979 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 980 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 984 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 985 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 986 | MockRead("\n"), |
| 987 | MockRead("\n"), |
| 988 | MockRead("Q"), |
| 989 | MockRead("J"), |
| 990 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 991 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 992 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 993 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 994 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 995 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 996 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 997 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 998 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 999 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1003 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1004 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1005 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1006 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1007 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1008 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1009 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 1010 | EXPECT_THAT(out.rv, IsOk()); |
| 1011 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 1012 | EXPECT_EQ("HTT", out.response_data); |
| 1013 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1014 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1015 | } |
| 1016 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1017 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 1018 | // persistent connection. The response should still terminate since a 204 |
| 1019 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1020 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1021 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1022 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1023 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1024 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1025 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1026 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1027 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1028 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1029 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1030 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 1031 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1032 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1033 | int64_t response_size = reads_size - strlen(junk); |
| 1034 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1035 | } |
| 1036 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1037 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1038 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1039 | std::string final_chunk = "0\r\n\r\n"; |
| 1040 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1041 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1042 | MockRead data_reads[] = { |
| 1043 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1044 | MockRead("5\r\nHello\r\n"), |
| 1045 | MockRead("1\r\n"), |
| 1046 | MockRead(" \r\n"), |
| 1047 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1048 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1049 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1050 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1051 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1052 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1053 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1054 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1055 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1056 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1057 | int64_t response_size = reads_size - extra_data.size(); |
| 1058 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1059 | } |
| 1060 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1061 | // Next tests deal with http://crbug.com/56344. |
| 1062 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1063 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1064 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1065 | MockRead data_reads[] = { |
| 1066 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1067 | MockRead("Content-Length: 10\r\n"), |
| 1068 | MockRead("Content-Length: 5\r\n\r\n"), |
| 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, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1073 | } |
| 1074 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1075 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1076 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1077 | MockRead data_reads[] = { |
| 1078 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1079 | MockRead("Content-Length: 5\r\n"), |
| 1080 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1081 | MockRead("Hello"), |
| 1082 | }; |
| 1083 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1084 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1085 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1086 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1087 | EXPECT_EQ("Hello", out.response_data); |
| 1088 | } |
| 1089 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1090 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1091 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1092 | // More than 2 dupes. |
| 1093 | { |
| 1094 | MockRead data_reads[] = { |
| 1095 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1096 | MockRead("Content-Length: 5\r\n"), |
| 1097 | MockRead("Content-Length: 5\r\n"), |
| 1098 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1099 | MockRead("Hello"), |
| 1100 | }; |
| 1101 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1102 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1103 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1104 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1105 | EXPECT_EQ("Hello", out.response_data); |
| 1106 | } |
| 1107 | // HTTP/1.0 |
| 1108 | { |
| 1109 | MockRead data_reads[] = { |
| 1110 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1111 | MockRead("Content-Length: 5\r\n"), |
| 1112 | MockRead("Content-Length: 5\r\n"), |
| 1113 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1114 | MockRead("Hello"), |
| 1115 | }; |
| 1116 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1117 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1118 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1119 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1120 | EXPECT_EQ("Hello", out.response_data); |
| 1121 | } |
| 1122 | // 2 dupes and one mismatched. |
| 1123 | { |
| 1124 | MockRead data_reads[] = { |
| 1125 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1126 | MockRead("Content-Length: 10\r\n"), |
| 1127 | MockRead("Content-Length: 10\r\n"), |
| 1128 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1129 | }; |
| 1130 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1131 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1132 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1136 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1137 | MultipleContentLengthHeadersTransferEncoding) { |
| 1138 | MockRead data_reads[] = { |
| 1139 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1140 | MockRead("Content-Length: 666\r\n"), |
| 1141 | MockRead("Content-Length: 1337\r\n"), |
| 1142 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1143 | MockRead("5\r\nHello\r\n"), |
| 1144 | MockRead("1\r\n"), |
| 1145 | MockRead(" \r\n"), |
| 1146 | MockRead("5\r\nworld\r\n"), |
| 1147 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1148 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1149 | }; |
| 1150 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1151 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1152 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1153 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1154 | EXPECT_EQ("Hello world", out.response_data); |
| 1155 | } |
| 1156 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1157 | // Next tests deal with http://crbug.com/98895. |
| 1158 | |
| 1159 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1160 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1161 | MockRead data_reads[] = { |
| 1162 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1163 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1164 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1165 | MockRead("Hello"), |
| 1166 | }; |
| 1167 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1168 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1169 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1170 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1171 | EXPECT_EQ("Hello", out.response_data); |
| 1172 | } |
| 1173 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1174 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1175 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1176 | MockRead data_reads[] = { |
| 1177 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1178 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1179 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1180 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1181 | MockRead("Hello"), |
| 1182 | }; |
| 1183 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1184 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1185 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1186 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1187 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1191 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1192 | MockRead data_reads[] = { |
| 1193 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1194 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1195 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1196 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1197 | MockRead("Hello"), |
| 1198 | }; |
| 1199 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1200 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1201 | EXPECT_THAT(out.rv, |
| 1202 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1203 | } |
| 1204 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1205 | // Checks that two identical Location headers result in no error. |
| 1206 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1207 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1208 | MockRead data_reads[] = { |
| 1209 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1210 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1211 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1212 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1213 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1214 | }; |
| 1215 | |
| 1216 | HttpRequestInfo request; |
| 1217 | request.method = "GET"; |
| 1218 | request.url = GURL("http://redirect.com/"); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1219 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1220 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1221 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1222 | |
| 1223 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1224 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1226 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1227 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1228 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1229 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1230 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1231 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1232 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1233 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1234 | ASSERT_TRUE(response); |
| 1235 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1236 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1237 | std::string url; |
| 1238 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1239 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1240 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1241 | } |
| 1242 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1243 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1244 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1245 | MockRead data_reads[] = { |
| 1246 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1247 | MockRead("Location: http://good.com/\r\n"), |
| 1248 | MockRead("Location: http://evil.com/\r\n"), |
| 1249 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1250 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1251 | }; |
| 1252 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1253 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1254 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1255 | } |
| 1256 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1257 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1258 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1259 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1260 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1261 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1262 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1263 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1264 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1265 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1266 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1267 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1268 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1269 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1270 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1271 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1272 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1273 | "Host: www.example.org\r\n" |
| 1274 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1275 | }; |
| 1276 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1277 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1278 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1279 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1280 | // No response body because the test stops reading here. |
| 1281 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1282 | }; |
| 1283 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1284 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1285 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1286 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1288 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1289 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1290 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1291 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1292 | |
| 1293 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1294 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1295 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1296 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1297 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1298 | |
| 1299 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1300 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1301 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1302 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1303 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1304 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1305 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1306 | |
| 1307 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1308 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1309 | bool has_server_header = response->headers->EnumerateHeader( |
| 1310 | &iter, "Server", &server_header); |
| 1311 | EXPECT_TRUE(has_server_header); |
| 1312 | EXPECT_EQ("Blah", server_header); |
| 1313 | |
| 1314 | // Reading should give EOF right away, since there is no message body |
| 1315 | // (despite non-zero content-length). |
| 1316 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1317 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1318 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1319 | EXPECT_EQ("", response_data); |
| 1320 | } |
| 1321 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1322 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1323 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1324 | |
| 1325 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1326 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1327 | MockRead("hello"), |
| 1328 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1329 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1330 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1331 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1332 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1333 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1334 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1335 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1336 | "hello", "world" |
| 1337 | }; |
| 1338 | |
| 1339 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1340 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1341 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1342 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1343 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1344 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1345 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1346 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1347 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1348 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1349 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1350 | |
| 1351 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1352 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1353 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1354 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1355 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1357 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1358 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1359 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1360 | |
| 1361 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1362 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1363 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1364 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1368 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1369 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1370 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1371 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1372 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1373 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1374 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1375 | request.method = "POST"; |
| 1376 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1377 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1378 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1379 | // Check the upload progress returned before initialization is correct. |
| 1380 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1381 | EXPECT_EQ(0u, progress.size()); |
| 1382 | EXPECT_EQ(0u, progress.position()); |
| 1383 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1384 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1385 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1386 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1387 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1388 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1389 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1390 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1391 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1392 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1393 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1394 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1395 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1396 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1397 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1398 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1399 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1400 | |
| 1401 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1402 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1403 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1404 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1405 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1406 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1407 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1408 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1409 | |
| 1410 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1411 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1412 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1413 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1414 | } |
| 1415 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1416 | // This test is almost the same as Ignores100 above, but the response contains |
| 1417 | // 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] | 1418 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1419 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1420 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1421 | request.method = "GET"; |
| 1422 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1423 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1424 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1425 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1426 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1427 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1428 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1429 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1430 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1431 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1432 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1433 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1434 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1436 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1437 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1438 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1439 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1440 | |
| 1441 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1442 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1443 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1444 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1445 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1446 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1447 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1448 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1449 | |
| 1450 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1451 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1452 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1453 | EXPECT_EQ("hello world", response_data); |
| 1454 | } |
| 1455 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1456 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1457 | HttpRequestInfo request; |
| 1458 | request.method = "POST"; |
| 1459 | request.url = GURL("http://www.foo.com/"); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1460 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1461 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1462 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1463 | |
| 1464 | MockRead data_reads[] = { |
| 1465 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1466 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1467 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1468 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1469 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1470 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1471 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1472 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1473 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1474 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1475 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1476 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1477 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1478 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1479 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1480 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1481 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1482 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1483 | } |
| 1484 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1485 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1486 | HttpRequestInfo request; |
| 1487 | request.method = "POST"; |
| 1488 | request.url = GURL("http://www.foo.com/"); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1489 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1490 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1491 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1492 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1493 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1494 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1495 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1496 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1497 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1498 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1499 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1500 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1501 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1502 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1503 | |
| 1504 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1505 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1506 | } |
| 1507 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1508 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1509 | const MockWrite* write_failure, |
| 1510 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1511 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1512 | request.method = "GET"; |
| 1513 | request.url = GURL("http://www.foo.com/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1514 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1515 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1516 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1517 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1518 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1519 | // Written data for successfully sending both requests. |
| 1520 | MockWrite data1_writes[] = { |
| 1521 | MockWrite("GET / HTTP/1.1\r\n" |
| 1522 | "Host: www.foo.com\r\n" |
| 1523 | "Connection: keep-alive\r\n\r\n"), |
| 1524 | MockWrite("GET / HTTP/1.1\r\n" |
| 1525 | "Host: www.foo.com\r\n" |
| 1526 | "Connection: keep-alive\r\n\r\n") |
| 1527 | }; |
| 1528 | |
| 1529 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1530 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1531 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1532 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1533 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1534 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1535 | |
| 1536 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1537 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1538 | data1_writes[1] = *write_failure; |
| 1539 | } else { |
| 1540 | ASSERT_TRUE(read_failure); |
| 1541 | data1_reads[2] = *read_failure; |
| 1542 | } |
| 1543 | |
| 1544 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1545 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1546 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1547 | |
| 1548 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1549 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1550 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1551 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1552 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1553 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1554 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1555 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1556 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1557 | "hello", "world" |
| 1558 | }; |
| 1559 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1560 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1561 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1562 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1563 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1564 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1565 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1566 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1567 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1568 | |
| 1569 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1570 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1571 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1572 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1573 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1574 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1575 | if (i == 0) { |
| 1576 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1577 | } else { |
| 1578 | // The second request should be using a new socket. |
| 1579 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1580 | } |
| 1581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1582 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1583 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1584 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1585 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1586 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1587 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1588 | |
| 1589 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1590 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1591 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1592 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1593 | } |
| 1594 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1595 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1596 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1597 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1598 | const MockRead* read_failure, |
| 1599 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1600 | HttpRequestInfo request; |
| 1601 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1602 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1603 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1604 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1605 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1606 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1607 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1608 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1609 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1610 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1611 | ssl1.next_proto = kProtoHTTP2; |
| 1612 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1613 | } |
| 1614 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1615 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1616 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1617 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1618 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1619 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1620 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1621 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1622 | SpdySerializedFrame spdy_data( |
| 1623 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1624 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1625 | // HTTP/1.1 versions of the request and response. |
| 1626 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1627 | "Host: www.foo.com\r\n" |
| 1628 | "Connection: keep-alive\r\n\r\n"; |
| 1629 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1630 | const char kHttpData[] = "hello"; |
| 1631 | |
| 1632 | std::vector<MockRead> data1_reads; |
| 1633 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1634 | if (write_failure) { |
| 1635 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1636 | data1_writes.push_back(*write_failure); |
| 1637 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1638 | } else { |
| 1639 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1640 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1641 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1642 | } else { |
| 1643 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1644 | } |
| 1645 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1646 | } |
| 1647 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1648 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1649 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1650 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1651 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1652 | std::vector<MockRead> data2_reads; |
| 1653 | std::vector<MockWrite> data2_writes; |
| 1654 | |
| 1655 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1656 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1657 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1658 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1659 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1660 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1661 | } else { |
| 1662 | data2_writes.push_back( |
| 1663 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1664 | |
| 1665 | data2_reads.push_back( |
| 1666 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1667 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1668 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1669 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1670 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1671 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1672 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1673 | |
| 1674 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1675 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1676 | // Wait for the preconnect to complete. |
| 1677 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1678 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1679 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1680 | |
| 1681 | // Make the request. |
| 1682 | TestCompletionCallback callback; |
| 1683 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1684 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1685 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1686 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1687 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1688 | |
| 1689 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1690 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1691 | |
| 1692 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1693 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1694 | TestLoadTimingNotReused( |
| 1695 | load_timing_info, |
| 1696 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1697 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1698 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1699 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1700 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1701 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1702 | if (response->was_fetched_via_spdy) { |
| 1703 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1704 | } else { |
| 1705 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1706 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1707 | |
| 1708 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1709 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1710 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1711 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1712 | } |
| 1713 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1714 | // Test that we do not retry indefinitely when a server sends an error like |
| 1715 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1716 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1717 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1718 | HttpRequestInfo request; |
| 1719 | request.method = "GET"; |
| 1720 | request.url = GURL("https://www.foo.com/"); |
| 1721 | |
| 1722 | // Check whether we give up after the third try. |
| 1723 | |
| 1724 | // Construct an HTTP2 request and a "Go away" response. |
| 1725 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1726 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
| 1727 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway()); |
| 1728 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1729 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1730 | |
| 1731 | // Three go away responses. |
| 1732 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1733 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1734 | StaticSocketDataProvider data3(&data_read1, 1, &data_write, 1); |
| 1735 | |
| 1736 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1737 | AddSSLSocketData(); |
| 1738 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1739 | AddSSLSocketData(); |
| 1740 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1741 | AddSSLSocketData(); |
| 1742 | |
| 1743 | TestCompletionCallback callback; |
| 1744 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1745 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1746 | |
| 1747 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1748 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1749 | |
| 1750 | rv = callback.WaitForResult(); |
| 1751 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1752 | } |
| 1753 | |
| 1754 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1755 | HttpRequestInfo request; |
| 1756 | request.method = "GET"; |
| 1757 | request.url = GURL("https://www.foo.com/"); |
| 1758 | |
| 1759 | // Check whether we try atleast thrice before giving up. |
| 1760 | |
| 1761 | // Construct an HTTP2 request and a "Go away" response. |
| 1762 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1763 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
| 1764 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway()); |
| 1765 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1766 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1767 | |
| 1768 | // Construct a non error HTTP2 response. |
| 1769 | SpdySerializedFrame spdy_response_no_error( |
| 1770 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1771 | SpdySerializedFrame spdy_data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 1772 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1773 | CreateMockRead(spdy_data, 2)}; |
| 1774 | |
| 1775 | // Two error responses. |
| 1776 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1777 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1778 | // Followed by a success response. |
| 1779 | SequencedSocketData data3(data_read2, 2, &data_write, 1); |
| 1780 | |
| 1781 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1782 | AddSSLSocketData(); |
| 1783 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1784 | AddSSLSocketData(); |
| 1785 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1786 | AddSSLSocketData(); |
| 1787 | |
| 1788 | TestCompletionCallback callback; |
| 1789 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1790 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1791 | |
| 1792 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1794 | |
| 1795 | rv = callback.WaitForResult(); |
| 1796 | EXPECT_THAT(rv, IsOk()); |
| 1797 | } |
| 1798 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1799 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1800 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1801 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1802 | } |
| 1803 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1804 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1805 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1806 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1807 | } |
| 1808 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1809 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1810 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1811 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1812 | } |
| 1813 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1814 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1815 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1816 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1817 | MockRead read_failure(SYNCHRONOUS, |
| 1818 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1819 | "Connection: Keep-Alive\r\n" |
| 1820 | "Content-Length: 6\r\n\r\n" |
| 1821 | "Pickle"); |
| 1822 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1823 | } |
| 1824 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1825 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1826 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1827 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1828 | } |
| 1829 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1830 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1831 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1832 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1833 | } |
| 1834 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1835 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1836 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1837 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1838 | } |
| 1839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1840 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1841 | MockRead read_failure(ASYNC, OK); // EOF |
| 1842 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1843 | } |
| 1844 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1845 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1846 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1847 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1848 | MockRead read_failure(SYNCHRONOUS, |
| 1849 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1850 | "Connection: Keep-Alive\r\n" |
| 1851 | "Content-Length: 6\r\n\r\n" |
| 1852 | "Pickle"); |
| 1853 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1854 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1855 | } |
| 1856 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1857 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1858 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1859 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1860 | } |
| 1861 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1862 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1863 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1864 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1865 | } |
| 1866 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1867 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1868 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1869 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1870 | } |
| 1871 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1872 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1873 | MockRead read_failure(ASYNC, OK); // EOF |
| 1874 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1875 | } |
| 1876 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1877 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1878 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1879 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1880 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1881 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1882 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1883 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1884 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1885 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1886 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1887 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1888 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1889 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1890 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1891 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1892 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1893 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1894 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1895 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1896 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1898 | |
| 1899 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1900 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1901 | |
| 1902 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1903 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1904 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | // What do various browsers do when the server closes a non-keepalive |
| 1908 | // connection without sending any response header or body? |
| 1909 | // |
| 1910 | // IE7: error page |
| 1911 | // Safari 3.1.2 (Windows): error page |
| 1912 | // Firefox 3.0.1: blank page |
| 1913 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1914 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1915 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1916 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1917 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1918 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1919 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1920 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1921 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1922 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1923 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1924 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1925 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1926 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1927 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1928 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1929 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1930 | // destructor in such situations. |
| 1931 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1932 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1933 | HttpRequestInfo request; |
| 1934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1935 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1936 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1937 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1938 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1939 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1940 | |
| 1941 | MockRead data_reads[] = { |
| 1942 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1943 | MockRead("Connection: keep-alive\r\n"), |
| 1944 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1945 | MockRead("hello"), |
| 1946 | MockRead(SYNCHRONOUS, 0), |
| 1947 | }; |
| 1948 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1949 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1950 | |
| 1951 | TestCompletionCallback callback; |
| 1952 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1953 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1954 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1955 | |
| 1956 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1957 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1958 | |
| 1959 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1960 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1961 | if (rv == ERR_IO_PENDING) |
| 1962 | rv = callback.WaitForResult(); |
| 1963 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1964 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1965 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1966 | |
| 1967 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1968 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1969 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1970 | } |
| 1971 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1972 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1973 | HttpRequestInfo request; |
| 1974 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1975 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1976 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1977 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1978 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1979 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1980 | |
| 1981 | MockRead data_reads[] = { |
| 1982 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1983 | MockRead("Connection: keep-alive\r\n"), |
| 1984 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1985 | MockRead(SYNCHRONOUS, 0), |
| 1986 | }; |
| 1987 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1988 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1989 | |
| 1990 | TestCompletionCallback callback; |
| 1991 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1992 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1993 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1994 | |
| 1995 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1996 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1997 | |
| 1998 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1999 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2000 | if (rv == ERR_IO_PENDING) |
| 2001 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2002 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2003 | |
| 2004 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2005 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2006 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2007 | } |
| 2008 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2009 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2010 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2011 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2012 | HttpRequestInfo request; |
| 2013 | request.method = "GET"; |
| 2014 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2015 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2016 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2017 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2018 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2019 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2020 | const char* request_data = |
| 2021 | "GET / HTTP/1.1\r\n" |
| 2022 | "Host: www.foo.com\r\n" |
| 2023 | "Connection: keep-alive\r\n\r\n"; |
| 2024 | MockWrite data_writes[] = { |
| 2025 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2026 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2027 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2028 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2029 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2030 | }; |
| 2031 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2032 | // Note that because all these reads happen in the same |
| 2033 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2034 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2035 | MockRead data_reads[] = { |
| 2036 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2037 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2038 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2039 | MockRead(ASYNC, 7, |
| 2040 | "HTTP/1.1 302 Found\r\n" |
| 2041 | "Content-Length: 0\r\n\r\n"), |
| 2042 | MockRead(ASYNC, 9, |
| 2043 | "HTTP/1.1 302 Found\r\n" |
| 2044 | "Content-Length: 5\r\n\r\n" |
| 2045 | "hello"), |
| 2046 | MockRead(ASYNC, 11, |
| 2047 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2048 | "Content-Length: 0\r\n\r\n"), |
| 2049 | MockRead(ASYNC, 13, |
| 2050 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2051 | "Content-Length: 5\r\n\r\n" |
| 2052 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2053 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2054 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2055 | // the set_busy_before_sync_reads(true) call, while the |
| 2056 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2057 | // reuseable. See http://crbug.com/544255. |
| 2058 | MockRead(ASYNC, 15, |
| 2059 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2060 | "Content-Length: 5\r\n\r\n"), |
| 2061 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2062 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2063 | MockRead(ASYNC, 18, |
| 2064 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2065 | "Content-Length: 5\r\n\r\n" |
| 2066 | "he"), |
| 2067 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2068 | |
| 2069 | // The body of the final request is actually read. |
| 2070 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2071 | MockRead(ASYNC, 22, "hello"), |
| 2072 | }; |
| 2073 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2074 | arraysize(data_writes)); |
| 2075 | data.set_busy_before_sync_reads(true); |
| 2076 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2077 | |
| 2078 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2079 | std::string response_lines[kNumUnreadBodies]; |
| 2080 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2081 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2082 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2083 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2084 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2085 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2086 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2087 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2088 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2089 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2090 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2091 | LoadTimingInfo load_timing_info; |
| 2092 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2093 | if (i == 0) { |
| 2094 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2095 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2096 | } else { |
| 2097 | TestLoadTimingReused(load_timing_info); |
| 2098 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2099 | } |
| 2100 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2101 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2102 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2103 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2104 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2105 | response_lines[i] = response->headers->GetStatusLine(); |
| 2106 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2107 | // Delete the transaction without reading the response bodies. Then spin |
| 2108 | // the message loop, so the response bodies are drained. |
| 2109 | trans.reset(); |
| 2110 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2111 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2112 | |
| 2113 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2114 | "HTTP/1.1 204 No Content", |
| 2115 | "HTTP/1.1 205 Reset Content", |
| 2116 | "HTTP/1.1 304 Not Modified", |
| 2117 | "HTTP/1.1 302 Found", |
| 2118 | "HTTP/1.1 302 Found", |
| 2119 | "HTTP/1.1 301 Moved Permanently", |
| 2120 | "HTTP/1.1 301 Moved Permanently", |
| 2121 | "HTTP/1.1 200 Hunky-Dory", |
| 2122 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2123 | }; |
| 2124 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2125 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2126 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2127 | |
| 2128 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2129 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2130 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2131 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2132 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2133 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2134 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2135 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2136 | ASSERT_TRUE(response); |
| 2137 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2138 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2139 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2140 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2141 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2142 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2143 | } |
| 2144 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2145 | // Sockets that receive extra data after a response is complete should not be |
| 2146 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2147 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2148 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2149 | MockWrite data_writes1[] = { |
| 2150 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2151 | "Host: www.borked.com\r\n" |
| 2152 | "Connection: keep-alive\r\n\r\n"), |
| 2153 | }; |
| 2154 | |
| 2155 | MockRead data_reads1[] = { |
| 2156 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2157 | "Connection: keep-alive\r\n" |
| 2158 | "Content-Length: 22\r\n\r\n" |
| 2159 | "This server is borked."), |
| 2160 | }; |
| 2161 | |
| 2162 | MockWrite data_writes2[] = { |
| 2163 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2164 | "Host: www.borked.com\r\n" |
| 2165 | "Connection: keep-alive\r\n\r\n"), |
| 2166 | }; |
| 2167 | |
| 2168 | MockRead data_reads2[] = { |
| 2169 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2170 | "Content-Length: 3\r\n\r\n" |
| 2171 | "foo"), |
| 2172 | }; |
| 2173 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2174 | data_writes1, arraysize(data_writes1)); |
| 2175 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2176 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2177 | data_writes2, arraysize(data_writes2)); |
| 2178 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2179 | |
| 2180 | TestCompletionCallback callback; |
| 2181 | HttpRequestInfo request1; |
| 2182 | request1.method = "HEAD"; |
| 2183 | request1.url = GURL("http://www.borked.com/"); |
| 2184 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2185 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2186 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2187 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2188 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2189 | |
| 2190 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2191 | ASSERT_TRUE(response1); |
| 2192 | ASSERT_TRUE(response1->headers); |
| 2193 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2194 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2195 | |
| 2196 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2197 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2198 | EXPECT_EQ("", response_data1); |
| 2199 | // Deleting the transaction attempts to release the socket back into the |
| 2200 | // socket pool. |
| 2201 | trans1.reset(); |
| 2202 | |
| 2203 | HttpRequestInfo request2; |
| 2204 | request2.method = "GET"; |
| 2205 | request2.url = GURL("http://www.borked.com/foo"); |
| 2206 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2207 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2208 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2209 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2210 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2211 | |
| 2212 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2213 | ASSERT_TRUE(response2); |
| 2214 | ASSERT_TRUE(response2->headers); |
| 2215 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2216 | |
| 2217 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2218 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2219 | EXPECT_EQ("foo", response_data2); |
| 2220 | } |
| 2221 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2222 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2223 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2224 | MockWrite data_writes1[] = { |
| 2225 | MockWrite("GET / HTTP/1.1\r\n" |
| 2226 | "Host: www.borked.com\r\n" |
| 2227 | "Connection: keep-alive\r\n\r\n"), |
| 2228 | }; |
| 2229 | |
| 2230 | MockRead data_reads1[] = { |
| 2231 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2232 | "Connection: keep-alive\r\n" |
| 2233 | "Content-Length: 22\r\n\r\n" |
| 2234 | "This server is borked." |
| 2235 | "Bonus data!"), |
| 2236 | }; |
| 2237 | |
| 2238 | MockWrite data_writes2[] = { |
| 2239 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2240 | "Host: www.borked.com\r\n" |
| 2241 | "Connection: keep-alive\r\n\r\n"), |
| 2242 | }; |
| 2243 | |
| 2244 | MockRead data_reads2[] = { |
| 2245 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2246 | "Content-Length: 3\r\n\r\n" |
| 2247 | "foo"), |
| 2248 | }; |
| 2249 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2250 | data_writes1, arraysize(data_writes1)); |
| 2251 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2252 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2253 | data_writes2, arraysize(data_writes2)); |
| 2254 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2255 | |
| 2256 | TestCompletionCallback callback; |
| 2257 | HttpRequestInfo request1; |
| 2258 | request1.method = "GET"; |
| 2259 | request1.url = GURL("http://www.borked.com/"); |
| 2260 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2261 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2262 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2263 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2264 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2265 | |
| 2266 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2267 | ASSERT_TRUE(response1); |
| 2268 | ASSERT_TRUE(response1->headers); |
| 2269 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2270 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2271 | |
| 2272 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2273 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2274 | EXPECT_EQ("This server is borked.", response_data1); |
| 2275 | // Deleting the transaction attempts to release the socket back into the |
| 2276 | // socket pool. |
| 2277 | trans1.reset(); |
| 2278 | |
| 2279 | HttpRequestInfo request2; |
| 2280 | request2.method = "GET"; |
| 2281 | request2.url = GURL("http://www.borked.com/foo"); |
| 2282 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2283 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2284 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2285 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2286 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2287 | |
| 2288 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2289 | ASSERT_TRUE(response2); |
| 2290 | ASSERT_TRUE(response2->headers); |
| 2291 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2292 | |
| 2293 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2294 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2295 | EXPECT_EQ("foo", response_data2); |
| 2296 | } |
| 2297 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2298 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2299 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2300 | MockWrite data_writes1[] = { |
| 2301 | MockWrite("GET / HTTP/1.1\r\n" |
| 2302 | "Host: www.borked.com\r\n" |
| 2303 | "Connection: keep-alive\r\n\r\n"), |
| 2304 | }; |
| 2305 | |
| 2306 | MockRead data_reads1[] = { |
| 2307 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2308 | "Connection: keep-alive\r\n" |
| 2309 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2310 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2311 | MockRead("0\r\n\r\nBonus data!"), |
| 2312 | }; |
| 2313 | |
| 2314 | MockWrite data_writes2[] = { |
| 2315 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2316 | "Host: www.borked.com\r\n" |
| 2317 | "Connection: keep-alive\r\n\r\n"), |
| 2318 | }; |
| 2319 | |
| 2320 | MockRead data_reads2[] = { |
| 2321 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2322 | "Content-Length: 3\r\n\r\n" |
| 2323 | "foo"), |
| 2324 | }; |
| 2325 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2326 | data_writes1, arraysize(data_writes1)); |
| 2327 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2328 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2329 | data_writes2, arraysize(data_writes2)); |
| 2330 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2331 | |
| 2332 | TestCompletionCallback callback; |
| 2333 | HttpRequestInfo request1; |
| 2334 | request1.method = "GET"; |
| 2335 | request1.url = GURL("http://www.borked.com/"); |
| 2336 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2337 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2338 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2339 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2340 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2341 | |
| 2342 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2343 | ASSERT_TRUE(response1); |
| 2344 | ASSERT_TRUE(response1->headers); |
| 2345 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2346 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2347 | |
| 2348 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2349 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2350 | EXPECT_EQ("This server is borked.", response_data1); |
| 2351 | // Deleting the transaction attempts to release the socket back into the |
| 2352 | // socket pool. |
| 2353 | trans1.reset(); |
| 2354 | |
| 2355 | HttpRequestInfo request2; |
| 2356 | request2.method = "GET"; |
| 2357 | request2.url = GURL("http://www.borked.com/foo"); |
| 2358 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2359 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2360 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2361 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2362 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2363 | |
| 2364 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2365 | ASSERT_TRUE(response2); |
| 2366 | ASSERT_TRUE(response2->headers); |
| 2367 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2368 | |
| 2369 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2370 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2371 | EXPECT_EQ("foo", response_data2); |
| 2372 | } |
| 2373 | |
| 2374 | // This is a little different from the others - it tests the case that the |
| 2375 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2376 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2377 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2378 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2379 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2380 | MockWrite data_writes1[] = { |
| 2381 | MockWrite("GET / HTTP/1.1\r\n" |
| 2382 | "Host: www.borked.com\r\n" |
| 2383 | "Connection: keep-alive\r\n\r\n"), |
| 2384 | }; |
| 2385 | |
| 2386 | MockRead data_reads1[] = { |
| 2387 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2388 | "Connection: keep-alive\r\n" |
| 2389 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2390 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2391 | MockRead("0\r\n\r\nBonus data!"), |
| 2392 | }; |
| 2393 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2394 | data_writes1, arraysize(data_writes1)); |
| 2395 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2396 | |
| 2397 | TestCompletionCallback callback; |
| 2398 | HttpRequestInfo request1; |
| 2399 | request1.method = "GET"; |
| 2400 | request1.url = GURL("http://www.borked.com/"); |
| 2401 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2402 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2403 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2404 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2405 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2406 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2407 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2408 | ASSERT_TRUE(response1); |
| 2409 | ASSERT_TRUE(response1->headers); |
| 2410 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2411 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2412 | |
| 2413 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2414 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2415 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2416 | |
| 2417 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2418 | // socket can't be reused, rather than returning it to the socket pool. |
| 2419 | base::RunLoop().RunUntilIdle(); |
| 2420 | |
| 2421 | // There should be no idle sockets in the pool. |
| 2422 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2423 | } |
| 2424 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2425 | // Test the request-challenge-retry sequence for basic auth. |
| 2426 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2427 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2428 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2429 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2430 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2431 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2432 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2433 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2434 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2435 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2436 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2437 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2438 | MockWrite( |
| 2439 | "GET / HTTP/1.1\r\n" |
| 2440 | "Host: www.example.org\r\n" |
| 2441 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2442 | }; |
| 2443 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2444 | MockRead data_reads1[] = { |
| 2445 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2446 | // Give a couple authenticate options (only the middle one is actually |
| 2447 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2448 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2449 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2450 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2451 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2452 | // Large content-length -- won't matter, as connection will be reset. |
| 2453 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2454 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2455 | }; |
| 2456 | |
| 2457 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2458 | // be issuing -- the final header line contains the credentials. |
| 2459 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2460 | MockWrite( |
| 2461 | "GET / HTTP/1.1\r\n" |
| 2462 | "Host: www.example.org\r\n" |
| 2463 | "Connection: keep-alive\r\n" |
| 2464 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2465 | }; |
| 2466 | |
| 2467 | // Lastly, the server responds with the actual content. |
| 2468 | MockRead data_reads2[] = { |
| 2469 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2470 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2471 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2472 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2473 | }; |
| 2474 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2475 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2476 | data_writes1, arraysize(data_writes1)); |
| 2477 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2478 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2479 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2480 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2482 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2483 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2484 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2486 | |
| 2487 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2488 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2489 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2490 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2491 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2492 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2493 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2494 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2495 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2496 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2497 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2499 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2500 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2501 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2502 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2503 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2504 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2505 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2506 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2507 | |
| 2508 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2509 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2510 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2511 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2512 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2513 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2514 | // The load timing after restart should have a new socket ID, and times after |
| 2515 | // those of the first load timing. |
| 2516 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2517 | load_timing_info2.connect_timing.connect_start); |
| 2518 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2519 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2520 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2521 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2522 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2523 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2524 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2525 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2526 | ASSERT_TRUE(response); |
| 2527 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2528 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2529 | } |
| 2530 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2531 | // Test the request-challenge-retry sequence for basic auth. |
| 2532 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2533 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2534 | HttpRequestInfo request; |
| 2535 | request.method = "GET"; |
| 2536 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2537 | |
| 2538 | TestNetLog log; |
| 2539 | MockHostResolver* resolver = new MockHostResolver(); |
| 2540 | session_deps_.net_log = &log; |
| 2541 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2542 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2543 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2544 | |
| 2545 | resolver->rules()->ClearRules(); |
| 2546 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2547 | |
| 2548 | MockWrite data_writes1[] = { |
| 2549 | MockWrite("GET / HTTP/1.1\r\n" |
| 2550 | "Host: www.example.org\r\n" |
| 2551 | "Connection: keep-alive\r\n\r\n"), |
| 2552 | }; |
| 2553 | |
| 2554 | MockRead data_reads1[] = { |
| 2555 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2556 | // Give a couple authenticate options (only the middle one is actually |
| 2557 | // supported). |
| 2558 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2559 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2560 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2561 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2562 | // Large content-length -- won't matter, as connection will be reset. |
| 2563 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2564 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2565 | }; |
| 2566 | |
| 2567 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2568 | // be issuing -- the final header line contains the credentials. |
| 2569 | MockWrite data_writes2[] = { |
| 2570 | MockWrite("GET / HTTP/1.1\r\n" |
| 2571 | "Host: www.example.org\r\n" |
| 2572 | "Connection: keep-alive\r\n" |
| 2573 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2574 | }; |
| 2575 | |
| 2576 | // Lastly, the server responds with the actual content. |
| 2577 | MockRead data_reads2[] = { |
| 2578 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2579 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2580 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2581 | }; |
| 2582 | |
| 2583 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2584 | data_writes1, arraysize(data_writes1)); |
| 2585 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2586 | data_writes2, arraysize(data_writes2)); |
| 2587 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2588 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2589 | |
| 2590 | TestCompletionCallback callback1; |
| 2591 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2592 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2593 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2594 | |
| 2595 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2596 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2597 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2598 | |
| 2599 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2600 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2601 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2602 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2603 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2604 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2605 | ASSERT_TRUE(response); |
| 2606 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2607 | |
| 2608 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2609 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2610 | ASSERT_FALSE(endpoint.address().empty()); |
| 2611 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2612 | |
| 2613 | resolver->rules()->ClearRules(); |
| 2614 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2615 | |
| 2616 | TestCompletionCallback callback2; |
| 2617 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2618 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2619 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2620 | |
| 2621 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2622 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2623 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2624 | // The load timing after restart should have a new socket ID, and times after |
| 2625 | // those of the first load timing. |
| 2626 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2627 | load_timing_info2.connect_timing.connect_start); |
| 2628 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2629 | |
| 2630 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2631 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2632 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2633 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2634 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2635 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2636 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2637 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2638 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2640 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2641 | ASSERT_FALSE(endpoint.address().empty()); |
| 2642 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2643 | } |
| 2644 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2645 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2646 | HttpRequestInfo request; |
| 2647 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2648 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2649 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2650 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2651 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2652 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2653 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2654 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2655 | MockWrite( |
| 2656 | "GET / HTTP/1.1\r\n" |
| 2657 | "Host: www.example.org\r\n" |
| 2658 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2659 | }; |
| 2660 | |
| 2661 | MockRead data_reads[] = { |
| 2662 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2663 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2664 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2665 | // Large content-length -- won't matter, as connection will be reset. |
| 2666 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2667 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2668 | }; |
| 2669 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2670 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2671 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2672 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2673 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2674 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2675 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2676 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2677 | |
| 2678 | rv = callback.WaitForResult(); |
| 2679 | EXPECT_EQ(0, rv); |
| 2680 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2681 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2682 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2683 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2684 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2685 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2686 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2687 | ASSERT_TRUE(response); |
| 2688 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2689 | } |
| 2690 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2691 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2692 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2693 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2694 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2695 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2696 | // reused. See http://crbug.com/544255. |
| 2697 | for (int i = 0; i < 2; ++i) { |
| 2698 | HttpRequestInfo request; |
| 2699 | request.method = "GET"; |
| 2700 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2701 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2702 | TestNetLog log; |
| 2703 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2705 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2706 | MockWrite data_writes[] = { |
| 2707 | MockWrite(ASYNC, 0, |
| 2708 | "GET / HTTP/1.1\r\n" |
| 2709 | "Host: www.example.org\r\n" |
| 2710 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2711 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2712 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2713 | // be issuing -- the final header line contains the credentials. |
| 2714 | MockWrite(ASYNC, 6, |
| 2715 | "GET / HTTP/1.1\r\n" |
| 2716 | "Host: www.example.org\r\n" |
| 2717 | "Connection: keep-alive\r\n" |
| 2718 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2719 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2720 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2721 | MockRead data_reads[] = { |
| 2722 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2723 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2724 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2725 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2726 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2727 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2728 | // Lastly, the server responds with the actual content. |
| 2729 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2730 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2731 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2732 | MockRead(ASYNC, 10, "Hello"), |
| 2733 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2734 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2735 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2736 | arraysize(data_writes)); |
| 2737 | data.set_busy_before_sync_reads(true); |
| 2738 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2739 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2740 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2742 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2743 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2744 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2745 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2746 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2747 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2748 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2749 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2750 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2751 | ASSERT_TRUE(response); |
| 2752 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2753 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2754 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2755 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2756 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2757 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2758 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2759 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2760 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2761 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2762 | TestLoadTimingReused(load_timing_info2); |
| 2763 | // The load timing after restart should have the same socket ID, and times |
| 2764 | // those of the first load timing. |
| 2765 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2766 | load_timing_info2.send_start); |
| 2767 | 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] | 2768 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2769 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2770 | ASSERT_TRUE(response); |
| 2771 | EXPECT_FALSE(response->auth_challenge); |
| 2772 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2773 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2774 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2775 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2776 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2777 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2778 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2779 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2780 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2781 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2785 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2786 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2787 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2788 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2789 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2790 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2791 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2792 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2793 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2794 | MockWrite("GET / HTTP/1.1\r\n" |
| 2795 | "Host: www.example.org\r\n" |
| 2796 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2797 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2798 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2799 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2800 | MockWrite("GET / HTTP/1.1\r\n" |
| 2801 | "Host: www.example.org\r\n" |
| 2802 | "Connection: keep-alive\r\n" |
| 2803 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2804 | }; |
| 2805 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2806 | MockRead data_reads1[] = { |
| 2807 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2808 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2809 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2810 | |
| 2811 | // Lastly, the server responds with the actual content. |
| 2812 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2813 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2814 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2815 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2816 | }; |
| 2817 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2818 | // An incorrect reconnect would cause this to be read. |
| 2819 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2820 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2821 | }; |
| 2822 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2823 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2824 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2825 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2826 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2827 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2828 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2830 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2832 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2833 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2834 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2835 | |
| 2836 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2837 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2839 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2840 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2841 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2842 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2843 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2845 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2846 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2847 | |
| 2848 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2849 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2850 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2851 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2852 | ASSERT_TRUE(response); |
| 2853 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2854 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2858 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2859 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2860 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2861 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2862 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2863 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2864 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2865 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2866 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2867 | MockWrite("GET / HTTP/1.1\r\n" |
| 2868 | "Host: www.example.org\r\n" |
| 2869 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2870 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2871 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2872 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2873 | MockWrite("GET / HTTP/1.1\r\n" |
| 2874 | "Host: www.example.org\r\n" |
| 2875 | "Connection: keep-alive\r\n" |
| 2876 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2877 | }; |
| 2878 | |
| 2879 | // Respond with 5 kb of response body. |
| 2880 | std::string large_body_string("Unauthorized"); |
| 2881 | large_body_string.append(5 * 1024, ' '); |
| 2882 | large_body_string.append("\r\n"); |
| 2883 | |
| 2884 | MockRead data_reads1[] = { |
| 2885 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2886 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2887 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2888 | // 5134 = 12 + 5 * 1024 + 2 |
| 2889 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2890 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2891 | |
| 2892 | // Lastly, the server responds with the actual content. |
| 2893 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2894 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2895 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2896 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2897 | }; |
| 2898 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2899 | // An incorrect reconnect would cause this to be read. |
| 2900 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2901 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2902 | }; |
| 2903 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2904 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2905 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2906 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2907 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2908 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2909 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2910 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2911 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2912 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2913 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2914 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2915 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2916 | |
| 2917 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2918 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2919 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2920 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2921 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2922 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2923 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2924 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2925 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2926 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2927 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2928 | |
| 2929 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2930 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2931 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2932 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2933 | ASSERT_TRUE(response); |
| 2934 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2935 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2939 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2940 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2941 | HttpRequestInfo request; |
| 2942 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2943 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2944 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2945 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2946 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2947 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2948 | MockWrite( |
| 2949 | "GET / HTTP/1.1\r\n" |
| 2950 | "Host: www.example.org\r\n" |
| 2951 | "Connection: keep-alive\r\n\r\n"), |
| 2952 | // This simulates the seemingly successful write to a closed connection |
| 2953 | // if the bug is not fixed. |
| 2954 | MockWrite( |
| 2955 | "GET / HTTP/1.1\r\n" |
| 2956 | "Host: www.example.org\r\n" |
| 2957 | "Connection: keep-alive\r\n" |
| 2958 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2959 | }; |
| 2960 | |
| 2961 | MockRead data_reads1[] = { |
| 2962 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2963 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2964 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2965 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2966 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2967 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2968 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2969 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2970 | }; |
| 2971 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2972 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2973 | // be issuing -- the final header line contains the credentials. |
| 2974 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2975 | MockWrite( |
| 2976 | "GET / HTTP/1.1\r\n" |
| 2977 | "Host: www.example.org\r\n" |
| 2978 | "Connection: keep-alive\r\n" |
| 2979 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2980 | }; |
| 2981 | |
| 2982 | // Lastly, the server responds with the actual content. |
| 2983 | MockRead data_reads2[] = { |
| 2984 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2985 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2986 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2987 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2988 | }; |
| 2989 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2990 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2991 | data_writes1, arraysize(data_writes1)); |
| 2992 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2993 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2994 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2995 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2997 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2998 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2999 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3000 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3001 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3002 | |
| 3003 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3004 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3005 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3006 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3007 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3008 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3009 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3010 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3012 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3013 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3014 | |
| 3015 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3016 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3017 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3018 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3019 | ASSERT_TRUE(response); |
| 3020 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3021 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3022 | } |
| 3023 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3024 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3025 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3026 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3027 | HttpRequestInfo request; |
| 3028 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3029 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3030 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3031 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3032 | |
| 3033 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 3034 | session_deps_.proxy_resolution_service = |
| 3035 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3036 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3037 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3038 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3039 | |
| 3040 | // Since we have proxy, should try to establish tunnel. |
| 3041 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3042 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3043 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3044 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3045 | }; |
| 3046 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3047 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3048 | // connection. |
| 3049 | MockRead data_reads1[] = { |
| 3050 | // No credentials. |
| 3051 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3052 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3053 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3054 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3055 | // Since the first connection couldn't be reused, need to establish another |
| 3056 | // once given credentials. |
| 3057 | MockWrite data_writes2[] = { |
| 3058 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3059 | // be issuing -- the final header line contains the credentials. |
| 3060 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3061 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3062 | "Proxy-Connection: keep-alive\r\n" |
| 3063 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3064 | |
| 3065 | MockWrite("GET / HTTP/1.1\r\n" |
| 3066 | "Host: www.example.org\r\n" |
| 3067 | "Connection: keep-alive\r\n\r\n"), |
| 3068 | }; |
| 3069 | |
| 3070 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3071 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3072 | |
| 3073 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3074 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3075 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3076 | MockRead(SYNCHRONOUS, "hello"), |
| 3077 | }; |
| 3078 | |
| 3079 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3080 | data_writes1, arraysize(data_writes1)); |
| 3081 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3082 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3083 | data_writes2, arraysize(data_writes2)); |
| 3084 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3085 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3086 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3087 | |
| 3088 | TestCompletionCallback callback1; |
| 3089 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3090 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3091 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3092 | |
| 3093 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3094 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3095 | |
| 3096 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3097 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3098 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3099 | log.GetEntries(&entries); |
| 3100 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3101 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3102 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3103 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3104 | entries, pos, |
| 3105 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3106 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3107 | |
| 3108 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3109 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3110 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3111 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3112 | EXPECT_EQ(407, response->headers->response_code()); |
| 3113 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3114 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3115 | |
| 3116 | LoadTimingInfo load_timing_info; |
| 3117 | // CONNECT requests and responses are handled at the connect job level, so |
| 3118 | // the transaction does not yet have a connection. |
| 3119 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3120 | |
| 3121 | TestCompletionCallback callback2; |
| 3122 | |
| 3123 | rv = |
| 3124 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3125 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3126 | |
| 3127 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3128 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3129 | |
| 3130 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3131 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3132 | |
| 3133 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3134 | EXPECT_EQ(200, response->headers->response_code()); |
| 3135 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3136 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3137 | |
| 3138 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3139 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3140 | |
| 3141 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3142 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3143 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3144 | |
| 3145 | trans.reset(); |
| 3146 | session->CloseAllConnections(); |
| 3147 | } |
| 3148 | |
| 3149 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3150 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3151 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3152 | HttpRequestInfo request; |
| 3153 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3154 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3155 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3156 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3157 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3158 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 3159 | session_deps_.proxy_resolution_service = |
| 3160 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3161 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3162 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3163 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3164 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3165 | // Since we have proxy, should try to establish tunnel. |
| 3166 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3167 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3168 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3169 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3170 | }; |
| 3171 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3172 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3173 | // connection. |
| 3174 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3175 | // No credentials. |
| 3176 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3177 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3178 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3179 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3180 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3181 | MockWrite data_writes2[] = { |
| 3182 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3183 | // be issuing -- the final header line contains the credentials. |
| 3184 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3185 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3186 | "Proxy-Connection: keep-alive\r\n" |
| 3187 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3188 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3189 | MockWrite("GET / HTTP/1.1\r\n" |
| 3190 | "Host: www.example.org\r\n" |
| 3191 | "Connection: keep-alive\r\n\r\n"), |
| 3192 | }; |
| 3193 | |
| 3194 | MockRead data_reads2[] = { |
| 3195 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3196 | |
| 3197 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3198 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3199 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3200 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3201 | }; |
| 3202 | |
| 3203 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3204 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3205 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3206 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3207 | data_writes2, arraysize(data_writes2)); |
| 3208 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3209 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3210 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3211 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3212 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3213 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3214 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3215 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3217 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3218 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3219 | |
| 3220 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3221 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3222 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3223 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3224 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3225 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3226 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3227 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3228 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3229 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3230 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3231 | |
| 3232 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3233 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3234 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3235 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3236 | EXPECT_EQ(407, response->headers->response_code()); |
| 3237 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3238 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3239 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3240 | LoadTimingInfo load_timing_info; |
| 3241 | // CONNECT requests and responses are handled at the connect job level, so |
| 3242 | // the transaction does not yet have a connection. |
| 3243 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3245 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3247 | rv = trans->RestartWithAuth( |
| 3248 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3249 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3250 | |
| 3251 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3252 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3253 | |
| 3254 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3255 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3256 | |
| 3257 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3258 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3259 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3260 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3261 | |
| 3262 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3263 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3264 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3265 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3266 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3267 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3268 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3269 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3270 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3271 | } |
| 3272 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3273 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3274 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3275 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3276 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3277 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3278 | // reused. See http://crbug.com/544255. |
| 3279 | for (int i = 0; i < 2; ++i) { |
| 3280 | HttpRequestInfo request; |
| 3281 | request.method = "GET"; |
| 3282 | request.url = GURL("https://www.example.org/"); |
| 3283 | // Ensure that proxy authentication is attempted even |
| 3284 | // when the no authentication data flag is set. |
| 3285 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3286 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3287 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 3288 | session_deps_.proxy_resolution_service = |
| 3289 | ProxyResolutionService::CreateFixed("myproxy:70"); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3290 | BoundTestNetLog log; |
| 3291 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3292 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3293 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3294 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3295 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3296 | // Since we have proxy, should try to establish tunnel. |
| 3297 | MockWrite data_writes1[] = { |
| 3298 | MockWrite(ASYNC, 0, |
| 3299 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3300 | "Host: www.example.org:443\r\n" |
| 3301 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3302 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3303 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3304 | // be issuing -- the final header line contains the credentials. |
| 3305 | MockWrite(ASYNC, 3, |
| 3306 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3307 | "Host: www.example.org:443\r\n" |
| 3308 | "Proxy-Connection: keep-alive\r\n" |
| 3309 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3310 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3311 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3312 | // The proxy responds to the connect with a 407, using a persistent |
| 3313 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3314 | MockRead data_reads1[] = { |
| 3315 | // No credentials. |
| 3316 | MockRead(ASYNC, 1, |
| 3317 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3318 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3319 | "Proxy-Connection: keep-alive\r\n" |
| 3320 | "Content-Length: 10\r\n\r\n"), |
| 3321 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3322 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3323 | // Wrong credentials (wrong password). |
| 3324 | MockRead(ASYNC, 4, |
| 3325 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3326 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3327 | "Proxy-Connection: keep-alive\r\n" |
| 3328 | "Content-Length: 10\r\n\r\n"), |
| 3329 | // No response body because the test stops reading here. |
| 3330 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3331 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3332 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3333 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3334 | arraysize(data_writes1)); |
| 3335 | data1.set_busy_before_sync_reads(true); |
| 3336 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3337 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3338 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3339 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3340 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3341 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3342 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3343 | TestNetLogEntry::List entries; |
| 3344 | log.GetEntries(&entries); |
| 3345 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3346 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3347 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3348 | ExpectLogContainsSomewhere( |
| 3349 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3350 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3351 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3352 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3353 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3354 | ASSERT_TRUE(response); |
| 3355 | ASSERT_TRUE(response->headers); |
| 3356 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3357 | EXPECT_EQ(407, response->headers->response_code()); |
| 3358 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3359 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3360 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3361 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3362 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3363 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3364 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3365 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3366 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3367 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3368 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3369 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3370 | ASSERT_TRUE(response); |
| 3371 | ASSERT_TRUE(response->headers); |
| 3372 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3373 | EXPECT_EQ(407, response->headers->response_code()); |
| 3374 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3375 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3376 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3377 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3378 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3379 | // out of scope. |
| 3380 | session->CloseAllConnections(); |
| 3381 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3385 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3386 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3387 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3388 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3389 | // reused. See http://crbug.com/544255. |
| 3390 | for (int i = 0; i < 2; ++i) { |
| 3391 | HttpRequestInfo request; |
| 3392 | request.method = "GET"; |
| 3393 | request.url = GURL("https://www.example.org/"); |
| 3394 | // Ensure that proxy authentication is attempted even |
| 3395 | // when the no authentication data flag is set. |
| 3396 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3397 | |
| 3398 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 3399 | session_deps_.proxy_resolution_service = |
| 3400 | ProxyResolutionService::CreateFixed("myproxy:70"); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3401 | BoundTestNetLog log; |
| 3402 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3403 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3404 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3405 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3406 | |
| 3407 | // Since we have proxy, should try to establish tunnel. |
| 3408 | MockWrite data_writes1[] = { |
| 3409 | MockWrite(ASYNC, 0, |
| 3410 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3411 | "Host: www.example.org:443\r\n" |
| 3412 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3413 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3414 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3415 | // be issuing -- the final header line contains the credentials. |
| 3416 | MockWrite(ASYNC, 3, |
| 3417 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3418 | "Host: www.example.org:443\r\n" |
| 3419 | "Proxy-Connection: keep-alive\r\n" |
| 3420 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3421 | }; |
| 3422 | |
| 3423 | // The proxy responds to the connect with a 407, using a persistent |
| 3424 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3425 | MockRead data_reads1[] = { |
| 3426 | // No credentials. |
| 3427 | MockRead(ASYNC, 1, |
| 3428 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3429 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3430 | "Content-Length: 10\r\n\r\n"), |
| 3431 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3432 | |
| 3433 | // Wrong credentials (wrong password). |
| 3434 | MockRead(ASYNC, 4, |
| 3435 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3436 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3437 | "Content-Length: 10\r\n\r\n"), |
| 3438 | // No response body because the test stops reading here. |
| 3439 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3440 | }; |
| 3441 | |
| 3442 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3443 | arraysize(data_writes1)); |
| 3444 | data1.set_busy_before_sync_reads(true); |
| 3445 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3446 | |
| 3447 | TestCompletionCallback callback1; |
| 3448 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3449 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3450 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3451 | |
| 3452 | TestNetLogEntry::List entries; |
| 3453 | log.GetEntries(&entries); |
| 3454 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3455 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3456 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3457 | ExpectLogContainsSomewhere( |
| 3458 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3459 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3460 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3462 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3463 | ASSERT_TRUE(response); |
| 3464 | ASSERT_TRUE(response->headers); |
| 3465 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3466 | EXPECT_EQ(407, response->headers->response_code()); |
| 3467 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3468 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3469 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3470 | |
| 3471 | TestCompletionCallback callback2; |
| 3472 | |
| 3473 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3474 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3475 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3476 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3478 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3479 | ASSERT_TRUE(response); |
| 3480 | ASSERT_TRUE(response->headers); |
| 3481 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3482 | EXPECT_EQ(407, response->headers->response_code()); |
| 3483 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3484 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3485 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3486 | |
| 3487 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3488 | // out of scope. |
| 3489 | session->CloseAllConnections(); |
| 3490 | } |
| 3491 | } |
| 3492 | |
| 3493 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3494 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3495 | // the case the server sends extra data on the original socket, so it can't be |
| 3496 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3497 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3498 | HttpRequestInfo request; |
| 3499 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3500 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3501 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3502 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3503 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3504 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 3505 | session_deps_.proxy_resolution_service = |
| 3506 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3507 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3508 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3509 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3510 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3511 | // Since we have proxy, should try to establish tunnel. |
| 3512 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3513 | MockWrite(ASYNC, 0, |
| 3514 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3515 | "Host: www.example.org:443\r\n" |
| 3516 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3517 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3518 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3519 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3520 | // extra data, so the socket cannot be reused. |
| 3521 | MockRead data_reads1[] = { |
| 3522 | // No credentials. |
| 3523 | MockRead(ASYNC, 1, |
| 3524 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3525 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3526 | "Content-Length: 10\r\n\r\n"), |
| 3527 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3528 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3529 | }; |
| 3530 | |
| 3531 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3532 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3533 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3534 | MockWrite(ASYNC, 0, |
| 3535 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3536 | "Host: www.example.org:443\r\n" |
| 3537 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3538 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3539 | |
| 3540 | MockWrite(ASYNC, 2, |
| 3541 | "GET / HTTP/1.1\r\n" |
| 3542 | "Host: www.example.org\r\n" |
| 3543 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3544 | }; |
| 3545 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3546 | MockRead data_reads2[] = { |
| 3547 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3548 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3549 | MockRead(ASYNC, 3, |
| 3550 | "HTTP/1.1 200 OK\r\n" |
| 3551 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3552 | "Content-Length: 5\r\n\r\n"), |
| 3553 | // No response body because the test stops reading here. |
| 3554 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3555 | }; |
| 3556 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3557 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3558 | arraysize(data_writes1)); |
| 3559 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3560 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3561 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3562 | arraysize(data_writes2)); |
| 3563 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3564 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3565 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3566 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3567 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3568 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3569 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3570 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3571 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3572 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3573 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3574 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3575 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3576 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3577 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3578 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3579 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3580 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3581 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3582 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3583 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3584 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3585 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3586 | ASSERT_TRUE(response); |
| 3587 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3588 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3589 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3590 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3591 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3592 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3593 | LoadTimingInfo load_timing_info; |
| 3594 | // CONNECT requests and responses are handled at the connect job level, so |
| 3595 | // the transaction does not yet have a connection. |
| 3596 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3598 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3599 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3600 | rv = |
| 3601 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3602 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3603 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3604 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3605 | EXPECT_EQ(200, response->headers->response_code()); |
| 3606 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3607 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3608 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3609 | // The password prompt info should not be set. |
| 3610 | EXPECT_FALSE(response->auth_challenge); |
| 3611 | |
| 3612 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3613 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3614 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3615 | |
| 3616 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3617 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3618 | } |
| 3619 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3620 | // Test the case a proxy closes a socket while the challenge body is being |
| 3621 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3622 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3623 | HttpRequestInfo request; |
| 3624 | request.method = "GET"; |
| 3625 | request.url = GURL("https://www.example.org/"); |
| 3626 | // Ensure that proxy authentication is attempted even |
| 3627 | // when the no authentication data flag is set. |
| 3628 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3629 | |
| 3630 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 3631 | session_deps_.proxy_resolution_service = |
| 3632 | ProxyResolutionService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3633 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3634 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3635 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3636 | |
| 3637 | // Since we have proxy, should try to establish tunnel. |
| 3638 | MockWrite data_writes1[] = { |
| 3639 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3640 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3641 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3642 | }; |
| 3643 | |
| 3644 | // The proxy responds to the connect with a 407, using a persistent |
| 3645 | // connection. |
| 3646 | MockRead data_reads1[] = { |
| 3647 | // No credentials. |
| 3648 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3649 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3650 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3651 | // Server hands up in the middle of the body. |
| 3652 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3653 | }; |
| 3654 | |
| 3655 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3656 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3657 | // be issuing -- the final header line contains the credentials. |
| 3658 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3659 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3660 | "Proxy-Connection: keep-alive\r\n" |
| 3661 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3662 | |
| 3663 | MockWrite("GET / HTTP/1.1\r\n" |
| 3664 | "Host: www.example.org\r\n" |
| 3665 | "Connection: keep-alive\r\n\r\n"), |
| 3666 | }; |
| 3667 | |
| 3668 | MockRead data_reads2[] = { |
| 3669 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3670 | |
| 3671 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3672 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3673 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3674 | MockRead(SYNCHRONOUS, "hello"), |
| 3675 | }; |
| 3676 | |
| 3677 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3678 | data_writes1, arraysize(data_writes1)); |
| 3679 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3680 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3681 | data_writes2, arraysize(data_writes2)); |
| 3682 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3683 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3684 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3685 | |
| 3686 | TestCompletionCallback callback; |
| 3687 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3688 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3689 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3690 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3691 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3692 | ASSERT_TRUE(response); |
| 3693 | ASSERT_TRUE(response->headers); |
| 3694 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3695 | EXPECT_EQ(407, response->headers->response_code()); |
| 3696 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3697 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3698 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3699 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3700 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3701 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3702 | ASSERT_TRUE(response); |
| 3703 | ASSERT_TRUE(response->headers); |
| 3704 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3705 | EXPECT_EQ(200, response->headers->response_code()); |
| 3706 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3707 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3708 | EXPECT_EQ("hello", body); |
| 3709 | } |
| 3710 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3711 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3712 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3713 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3714 | HttpRequestInfo request; |
| 3715 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3716 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3717 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3718 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 3719 | session_deps_.proxy_resolution_service = |
| 3720 | ProxyResolutionService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3721 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3722 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3724 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3725 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3726 | // Since we have proxy, should try to establish tunnel. |
| 3727 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3728 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3729 | "Host: www.example.org:443\r\n" |
| 3730 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3731 | }; |
| 3732 | |
| 3733 | // The proxy responds to the connect with a 407. |
| 3734 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3735 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3736 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3737 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3738 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3739 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3740 | }; |
| 3741 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3742 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3743 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3744 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3745 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3746 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3747 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3748 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3749 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3750 | |
| 3751 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3752 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3753 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3754 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3755 | ASSERT_TRUE(response); |
| 3756 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3757 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3758 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3759 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3760 | |
| 3761 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3762 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3763 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3764 | |
| 3765 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3766 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3767 | } |
| 3768 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3769 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3770 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3771 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3772 | HttpRequestInfo request; |
| 3773 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3774 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3775 | |
| 3776 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 3777 | session_deps_.proxy_resolution_service = |
| 3778 | ProxyResolutionService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3779 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3781 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3782 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3783 | |
| 3784 | // Since we have proxy, should try to establish tunnel. |
| 3785 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3786 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3787 | "Host: www.example.org:443\r\n" |
| 3788 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3789 | }; |
| 3790 | |
| 3791 | // The proxy responds to the connect with a 407. |
| 3792 | MockRead data_reads[] = { |
| 3793 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3794 | MockRead("X-Foo: bar\r\n"), |
| 3795 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3796 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3797 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3798 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3799 | }; |
| 3800 | |
| 3801 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3802 | arraysize(data_writes)); |
| 3803 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3804 | |
| 3805 | TestCompletionCallback callback; |
| 3806 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3807 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3808 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3809 | |
| 3810 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3811 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3813 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3814 | ASSERT_TRUE(response); |
| 3815 | ASSERT_TRUE(response->headers); |
| 3816 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3817 | EXPECT_EQ(407, response->headers->response_code()); |
| 3818 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3819 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3820 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3821 | |
| 3822 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3823 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3824 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3825 | |
| 3826 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3827 | session->CloseAllConnections(); |
| 3828 | } |
| 3829 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3830 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3831 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3832 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3833 | HttpRequestInfo request; |
| 3834 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3835 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3836 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3837 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3838 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3839 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3840 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3841 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3842 | MockWrite( |
| 3843 | "GET / HTTP/1.1\r\n" |
| 3844 | "Host: www.example.org\r\n" |
| 3845 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3846 | }; |
| 3847 | |
| 3848 | MockRead data_reads1[] = { |
| 3849 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3850 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3851 | // Large content-length -- won't matter, as connection will be reset. |
| 3852 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3853 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3854 | }; |
| 3855 | |
| 3856 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3857 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3858 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3859 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3860 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3861 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3862 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3863 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3864 | |
| 3865 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3866 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3867 | } |
| 3868 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3869 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3870 | // through a non-authenticating proxy. The request should fail with |
| 3871 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3872 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3873 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3874 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3875 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3876 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3877 | HttpRequestInfo request; |
| 3878 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3879 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3880 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 3881 | session_deps_.proxy_resolution_service = |
| 3882 | ProxyResolutionService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3883 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3884 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3885 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3886 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3887 | // Since we have proxy, should try to establish tunnel. |
| 3888 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3889 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3890 | "Host: www.example.org:443\r\n" |
| 3891 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3892 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3893 | MockWrite("GET / HTTP/1.1\r\n" |
| 3894 | "Host: www.example.org\r\n" |
| 3895 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3896 | }; |
| 3897 | |
| 3898 | MockRead data_reads1[] = { |
| 3899 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3900 | |
| 3901 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3902 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3903 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3904 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3905 | }; |
| 3906 | |
| 3907 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3908 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3909 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3910 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3911 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3912 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3913 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3915 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3917 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3918 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3919 | |
| 3920 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3921 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3922 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3923 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3924 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3925 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3926 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3927 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3928 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3929 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3930 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3931 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3932 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3933 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3934 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3935 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3936 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3937 | HttpRequestInfo request; |
| 3938 | request.method = "GET"; |
| 3939 | request.url = GURL("https://www.example.org/"); |
| 3940 | |
| 3941 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 3942 | session_deps_.proxy_resolution_service = |
| 3943 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3944 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3945 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3946 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3947 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3948 | mock_handler->set_allows_default_credentials(true); |
| 3949 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3950 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3951 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3952 | |
| 3953 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3954 | NetLog net_log; |
| 3955 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3956 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3957 | |
| 3958 | // Since we have proxy, should try to establish tunnel. |
| 3959 | MockWrite data_writes1[] = { |
| 3960 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3961 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3962 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3963 | }; |
| 3964 | |
| 3965 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3966 | // connection. |
| 3967 | MockRead data_reads1[] = { |
| 3968 | // No credentials. |
| 3969 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3970 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3971 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3972 | }; |
| 3973 | |
| 3974 | // Since the first connection couldn't be reused, need to establish another |
| 3975 | // once given credentials. |
| 3976 | MockWrite data_writes2[] = { |
| 3977 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3978 | // be issuing -- the final header line contains the credentials. |
| 3979 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3980 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3981 | "Proxy-Connection: keep-alive\r\n" |
| 3982 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3983 | |
| 3984 | MockWrite("GET / HTTP/1.1\r\n" |
| 3985 | "Host: www.example.org\r\n" |
| 3986 | "Connection: keep-alive\r\n\r\n"), |
| 3987 | }; |
| 3988 | |
| 3989 | MockRead data_reads2[] = { |
| 3990 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3991 | |
| 3992 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3993 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3994 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3995 | MockRead(SYNCHRONOUS, "hello"), |
| 3996 | }; |
| 3997 | |
| 3998 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3999 | data_writes1, arraysize(data_writes1)); |
| 4000 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4001 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4002 | data_writes2, arraysize(data_writes2)); |
| 4003 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4004 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4005 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4006 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4007 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4008 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4009 | |
| 4010 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4011 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4012 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4013 | |
| 4014 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4015 | ASSERT_TRUE(response); |
| 4016 | ASSERT_TRUE(response->headers); |
| 4017 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4018 | EXPECT_EQ(407, response->headers->response_code()); |
| 4019 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4020 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4021 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4022 | |
| 4023 | LoadTimingInfo load_timing_info; |
| 4024 | // CONNECT requests and responses are handled at the connect job level, so |
| 4025 | // the transaction does not yet have a connection. |
| 4026 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4027 | |
| 4028 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4029 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4030 | response = trans->GetResponseInfo(); |
| 4031 | ASSERT_TRUE(response); |
| 4032 | ASSERT_TRUE(response->headers); |
| 4033 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4034 | EXPECT_EQ(200, response->headers->response_code()); |
| 4035 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4036 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4037 | |
| 4038 | // The password prompt info should not be set. |
| 4039 | EXPECT_FALSE(response->auth_challenge); |
| 4040 | |
| 4041 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4042 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4043 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4044 | |
| 4045 | trans.reset(); |
| 4046 | session->CloseAllConnections(); |
| 4047 | } |
| 4048 | |
| 4049 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4050 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4051 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4052 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4053 | HttpRequestInfo request; |
| 4054 | request.method = "GET"; |
| 4055 | request.url = GURL("https://www.example.org/"); |
| 4056 | |
| 4057 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 4058 | session_deps_.proxy_resolution_service = |
| 4059 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4060 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4061 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4062 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4063 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4064 | mock_handler->set_allows_default_credentials(true); |
| 4065 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4066 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4067 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4068 | |
| 4069 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4070 | NetLog net_log; |
| 4071 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4072 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4073 | |
| 4074 | // Should try to establish tunnel. |
| 4075 | MockWrite data_writes1[] = { |
| 4076 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4077 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4078 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4079 | |
| 4080 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4081 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4082 | "Proxy-Connection: keep-alive\r\n" |
| 4083 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4084 | }; |
| 4085 | |
| 4086 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4087 | // connection. |
| 4088 | MockRead data_reads1[] = { |
| 4089 | // No credentials. |
| 4090 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4091 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4092 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4093 | }; |
| 4094 | |
| 4095 | // Since the first connection was closed, need to establish another once given |
| 4096 | // credentials. |
| 4097 | MockWrite data_writes2[] = { |
| 4098 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4099 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4100 | "Proxy-Connection: keep-alive\r\n" |
| 4101 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4102 | |
| 4103 | MockWrite("GET / HTTP/1.1\r\n" |
| 4104 | "Host: www.example.org\r\n" |
| 4105 | "Connection: keep-alive\r\n\r\n"), |
| 4106 | }; |
| 4107 | |
| 4108 | MockRead data_reads2[] = { |
| 4109 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4110 | |
| 4111 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4112 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4113 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4114 | MockRead(SYNCHRONOUS, "hello"), |
| 4115 | }; |
| 4116 | |
| 4117 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4118 | data_writes1, arraysize(data_writes1)); |
| 4119 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4120 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4121 | data_writes2, arraysize(data_writes2)); |
| 4122 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4123 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4125 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4126 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4127 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4128 | |
| 4129 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4130 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4131 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4132 | |
| 4133 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4134 | ASSERT_TRUE(response); |
| 4135 | ASSERT_TRUE(response->headers); |
| 4136 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4137 | EXPECT_EQ(407, response->headers->response_code()); |
| 4138 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4139 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4140 | EXPECT_FALSE(response->auth_challenge); |
| 4141 | |
| 4142 | LoadTimingInfo load_timing_info; |
| 4143 | // CONNECT requests and responses are handled at the connect job level, so |
| 4144 | // the transaction does not yet have a connection. |
| 4145 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4146 | |
| 4147 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4148 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4149 | |
| 4150 | response = trans->GetResponseInfo(); |
| 4151 | ASSERT_TRUE(response); |
| 4152 | ASSERT_TRUE(response->headers); |
| 4153 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4154 | EXPECT_EQ(200, response->headers->response_code()); |
| 4155 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4156 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4157 | |
| 4158 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4159 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4160 | |
| 4161 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4162 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4163 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4164 | |
| 4165 | trans.reset(); |
| 4166 | session->CloseAllConnections(); |
| 4167 | } |
| 4168 | |
| 4169 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4170 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4171 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4172 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4173 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4174 | HttpRequestInfo request; |
| 4175 | request.method = "GET"; |
| 4176 | request.url = GURL("https://www.example.org/"); |
| 4177 | |
| 4178 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 4179 | session_deps_.proxy_resolution_service = |
| 4180 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4181 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4182 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4183 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4184 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4185 | mock_handler->set_allows_default_credentials(true); |
| 4186 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4187 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4188 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4189 | |
| 4190 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4191 | NetLog net_log; |
| 4192 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4193 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4194 | |
| 4195 | // Should try to establish tunnel. |
| 4196 | MockWrite data_writes1[] = { |
| 4197 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4198 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4199 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4200 | |
| 4201 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4202 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4203 | "Proxy-Connection: keep-alive\r\n" |
| 4204 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4205 | }; |
| 4206 | |
| 4207 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4208 | // second request is sent. |
| 4209 | MockRead data_reads1[] = { |
| 4210 | // No credentials. |
| 4211 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4212 | MockRead("Content-Length: 0\r\n"), |
| 4213 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4214 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4215 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4216 | }; |
| 4217 | |
| 4218 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4219 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4220 | // request. |
| 4221 | MockWrite data_writes2[] = { |
| 4222 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4223 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4224 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4225 | }; |
| 4226 | |
| 4227 | // The proxy, having had more than enough of us, just hangs up. |
| 4228 | MockRead data_reads2[] = { |
| 4229 | // No credentials. |
| 4230 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4231 | }; |
| 4232 | |
| 4233 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4234 | data_writes1, arraysize(data_writes1)); |
| 4235 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4236 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4237 | data_writes2, arraysize(data_writes2)); |
| 4238 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4239 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4240 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4241 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4242 | |
| 4243 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4244 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4245 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4246 | |
| 4247 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4248 | ASSERT_TRUE(response); |
| 4249 | ASSERT_TRUE(response->headers); |
| 4250 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4251 | EXPECT_EQ(407, response->headers->response_code()); |
| 4252 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4253 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4254 | EXPECT_FALSE(response->auth_challenge); |
| 4255 | |
| 4256 | LoadTimingInfo load_timing_info; |
| 4257 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4258 | |
| 4259 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4260 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4261 | |
| 4262 | trans.reset(); |
| 4263 | session->CloseAllConnections(); |
| 4264 | } |
| 4265 | |
| 4266 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4267 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4268 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4269 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4270 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4271 | HttpRequestInfo request; |
| 4272 | request.method = "GET"; |
| 4273 | request.url = GURL("https://www.example.org/"); |
| 4274 | |
| 4275 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 4276 | session_deps_.proxy_resolution_service = |
| 4277 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4278 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4279 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4280 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4281 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4282 | mock_handler->set_allows_default_credentials(true); |
| 4283 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4284 | HttpAuth::AUTH_PROXY); |
| 4285 | // Add another handler for the second challenge. It supports default |
| 4286 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4287 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4288 | mock_handler->set_allows_default_credentials(true); |
| 4289 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4290 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4291 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4292 | |
| 4293 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4294 | NetLog net_log; |
| 4295 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4296 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4297 | |
| 4298 | // Should try to establish tunnel. |
| 4299 | MockWrite data_writes1[] = { |
| 4300 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4301 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4302 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4303 | }; |
| 4304 | |
| 4305 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4306 | // connection. |
| 4307 | MockRead data_reads1[] = { |
| 4308 | // No credentials. |
| 4309 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4310 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4311 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4312 | }; |
| 4313 | |
| 4314 | // Since the first connection was closed, need to establish another once given |
| 4315 | // credentials. |
| 4316 | MockWrite data_writes2[] = { |
| 4317 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4318 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4319 | "Proxy-Connection: keep-alive\r\n" |
| 4320 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4321 | }; |
| 4322 | |
| 4323 | MockRead data_reads2[] = { |
| 4324 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4325 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4326 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4327 | }; |
| 4328 | |
| 4329 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4330 | data_writes1, arraysize(data_writes1)); |
| 4331 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4332 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4333 | data_writes2, arraysize(data_writes2)); |
| 4334 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4335 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4336 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4337 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4338 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4339 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4340 | |
| 4341 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4342 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4343 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4344 | |
| 4345 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4346 | ASSERT_TRUE(response); |
| 4347 | ASSERT_TRUE(response->headers); |
| 4348 | EXPECT_EQ(407, response->headers->response_code()); |
| 4349 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4350 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4351 | EXPECT_FALSE(response->auth_challenge); |
| 4352 | |
| 4353 | LoadTimingInfo load_timing_info; |
| 4354 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4355 | |
| 4356 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4357 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4358 | response = trans->GetResponseInfo(); |
| 4359 | ASSERT_TRUE(response); |
| 4360 | ASSERT_TRUE(response->headers); |
| 4361 | EXPECT_EQ(407, response->headers->response_code()); |
| 4362 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4363 | EXPECT_TRUE(response->auth_challenge); |
| 4364 | |
| 4365 | trans.reset(); |
| 4366 | session->CloseAllConnections(); |
| 4367 | } |
| 4368 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4369 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4370 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4371 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4372 | // authentication handshake can continue with the same scheme but with a |
| 4373 | // different identity. |
| 4374 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4375 | HttpRequestInfo request; |
| 4376 | request.method = "GET"; |
| 4377 | request.url = GURL("http://www.example.org/"); |
| 4378 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4379 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4380 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4381 | |
| 4382 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4383 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4384 | mock_handler->set_allows_default_credentials(true); |
| 4385 | mock_handler->set_allows_explicit_credentials(true); |
| 4386 | mock_handler->set_connection_based(true); |
| 4387 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4388 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4389 | HttpAuth::AUTH_SERVER); |
| 4390 | |
| 4391 | // Add another handler for the second challenge. It supports default |
| 4392 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4393 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4394 | mock_handler->set_allows_default_credentials(true); |
| 4395 | mock_handler->set_allows_explicit_credentials(true); |
| 4396 | mock_handler->set_connection_based(true); |
| 4397 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4398 | HttpAuth::AUTH_SERVER); |
| 4399 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4400 | |
| 4401 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4402 | |
| 4403 | MockWrite data_writes1[] = { |
| 4404 | MockWrite("GET / HTTP/1.1\r\n" |
| 4405 | "Host: www.example.org\r\n" |
| 4406 | "Connection: keep-alive\r\n\r\n"), |
| 4407 | }; |
| 4408 | |
| 4409 | MockRead data_reads1[] = { |
| 4410 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4411 | "WWW-Authenticate: Mock\r\n" |
| 4412 | "Connection: keep-alive\r\n\r\n"), |
| 4413 | }; |
| 4414 | |
| 4415 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4416 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4417 | // transaction procceds without an authorization header. |
| 4418 | MockWrite data_writes2[] = { |
| 4419 | MockWrite("GET / HTTP/1.1\r\n" |
| 4420 | "Host: www.example.org\r\n" |
| 4421 | "Connection: keep-alive\r\n\r\n"), |
| 4422 | }; |
| 4423 | |
| 4424 | MockRead data_reads2[] = { |
| 4425 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4426 | "WWW-Authenticate: Mock\r\n" |
| 4427 | "Connection: keep-alive\r\n\r\n"), |
| 4428 | }; |
| 4429 | |
| 4430 | MockWrite data_writes3[] = { |
| 4431 | MockWrite("GET / HTTP/1.1\r\n" |
| 4432 | "Host: www.example.org\r\n" |
| 4433 | "Connection: keep-alive\r\n" |
| 4434 | "Authorization: auth_token\r\n\r\n"), |
| 4435 | }; |
| 4436 | |
| 4437 | MockRead data_reads3[] = { |
| 4438 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4439 | "Content-Length: 5\r\n" |
| 4440 | "Content-Type: text/plain\r\n" |
| 4441 | "Connection: keep-alive\r\n\r\n" |
| 4442 | "Hello"), |
| 4443 | }; |
| 4444 | |
| 4445 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4446 | data_writes1, arraysize(data_writes1)); |
| 4447 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4448 | |
| 4449 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4450 | data_writes2, arraysize(data_writes2)); |
| 4451 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4452 | |
| 4453 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4454 | data_writes3, arraysize(data_writes3)); |
| 4455 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4456 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4457 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4458 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4459 | |
| 4460 | TestCompletionCallback callback; |
| 4461 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4462 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4463 | |
| 4464 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4465 | ASSERT_TRUE(response); |
| 4466 | ASSERT_TRUE(response->headers); |
| 4467 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4468 | |
| 4469 | // The following three tests assert that an authentication challenge was |
| 4470 | // received and that the stack is ready to respond to the challenge using |
| 4471 | // ambient credentials. |
| 4472 | EXPECT_EQ(401, response->headers->response_code()); |
| 4473 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4474 | EXPECT_FALSE(response->auth_challenge); |
| 4475 | |
| 4476 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4477 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4478 | response = trans->GetResponseInfo(); |
| 4479 | ASSERT_TRUE(response); |
| 4480 | ASSERT_TRUE(response->headers); |
| 4481 | |
| 4482 | // The following three tests assert that an authentication challenge was |
| 4483 | // received and that the stack needs explicit credentials before it is ready |
| 4484 | // to respond to the challenge. |
| 4485 | EXPECT_EQ(401, response->headers->response_code()); |
| 4486 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4487 | EXPECT_TRUE(response->auth_challenge); |
| 4488 | |
| 4489 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4490 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4491 | response = trans->GetResponseInfo(); |
| 4492 | ASSERT_TRUE(response); |
| 4493 | ASSERT_TRUE(response->headers); |
| 4494 | EXPECT_EQ(200, response->headers->response_code()); |
| 4495 | |
| 4496 | trans.reset(); |
| 4497 | session->CloseAllConnections(); |
| 4498 | } |
| 4499 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4500 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4501 | // schemes, based on the path of the URL being requests. |
| 4502 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4503 | public: |
| 4504 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4505 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4506 | |
| 4507 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4508 | |
| 4509 | static HostPortPair ProxyHostPortPair() { |
| 4510 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4511 | } |
| 4512 | |
| 4513 | // ProxyResolver implementation. |
| 4514 | int GetProxyForURL(const GURL& url, |
| 4515 | ProxyInfo* results, |
| 4516 | const CompletionCallback& callback, |
| 4517 | std::unique_ptr<Request>* request, |
| 4518 | const NetLogWithSource& /*net_log*/) override { |
| 4519 | *results = ProxyInfo(); |
| 4520 | if (url.path() == "/socks4") { |
| 4521 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4522 | return OK; |
| 4523 | } |
| 4524 | if (url.path() == "/socks5") { |
| 4525 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4526 | return OK; |
| 4527 | } |
| 4528 | if (url.path() == "/http") { |
| 4529 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4530 | return OK; |
| 4531 | } |
| 4532 | if (url.path() == "/https") { |
| 4533 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4534 | return OK; |
| 4535 | } |
| 4536 | NOTREACHED(); |
| 4537 | return ERR_NOT_IMPLEMENTED; |
| 4538 | } |
| 4539 | |
| 4540 | private: |
| 4541 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4542 | }; |
| 4543 | |
| 4544 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4545 | : public ProxyResolverFactory { |
| 4546 | public: |
| 4547 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4548 | : ProxyResolverFactory(false) {} |
| 4549 | |
| 4550 | int CreateProxyResolver( |
| 4551 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 4552 | std::unique_ptr<ProxyResolver>* resolver, |
| 4553 | const CompletionCallback& callback, |
| 4554 | std::unique_ptr<Request>* request) override { |
| 4555 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4556 | return OK; |
| 4557 | } |
| 4558 | |
| 4559 | private: |
| 4560 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4561 | }; |
| 4562 | |
| 4563 | // Check that when different proxy schemes are all applied to a proxy at the |
| 4564 | // same address, the sonnections are not grouped together. i.e., a request to |
| 4565 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4566 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4567 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 4568 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4569 | std::make_unique<ProxyConfigServiceFixed>( |
| 4570 | ProxyConfig::CreateAutoDetect()), |
| 4571 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4572 | nullptr); |
| 4573 | |
| 4574 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4575 | |
| 4576 | MockWrite socks_writes[] = { |
| 4577 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4578 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4579 | MockWrite(SYNCHRONOUS, |
| 4580 | "GET /socks4 HTTP/1.1\r\n" |
| 4581 | "Host: test\r\n" |
| 4582 | "Connection: keep-alive\r\n\r\n"), |
| 4583 | }; |
| 4584 | MockRead socks_reads[] = { |
| 4585 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4586 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4587 | "Connection: keep-alive\r\n" |
| 4588 | "Content-Length: 15\r\n\r\n" |
| 4589 | "SOCKS4 Response"), |
| 4590 | }; |
| 4591 | StaticSocketDataProvider socks_data(socks_reads, arraysize(socks_reads), |
| 4592 | socks_writes, arraysize(socks_writes)); |
| 4593 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4594 | |
| 4595 | const char kSOCKS5Request[] = { |
| 4596 | 0x05, // Version |
| 4597 | 0x01, // Command (CONNECT) |
| 4598 | 0x00, // Reserved |
| 4599 | 0x03, // Address type (DOMAINNAME) |
| 4600 | 0x04, // Length of domain (4) |
| 4601 | 't', 'e', 's', 't', // Domain string |
| 4602 | 0x00, 0x50, // 16-bit port (80) |
| 4603 | }; |
| 4604 | MockWrite socks5_writes[] = { |
| 4605 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
| 4606 | MockWrite(ASYNC, kSOCKS5Request, arraysize(kSOCKS5Request)), |
| 4607 | MockWrite(SYNCHRONOUS, |
| 4608 | "GET /socks5 HTTP/1.1\r\n" |
| 4609 | "Host: test\r\n" |
| 4610 | "Connection: keep-alive\r\n\r\n"), |
| 4611 | }; |
| 4612 | MockRead socks5_reads[] = { |
| 4613 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4614 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4615 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4616 | "Connection: keep-alive\r\n" |
| 4617 | "Content-Length: 15\r\n\r\n" |
| 4618 | "SOCKS5 Response"), |
| 4619 | }; |
| 4620 | StaticSocketDataProvider socks5_data(socks5_reads, arraysize(socks5_reads), |
| 4621 | socks5_writes, arraysize(socks5_writes)); |
| 4622 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 4623 | |
| 4624 | MockWrite http_writes[] = { |
| 4625 | MockWrite(SYNCHRONOUS, |
| 4626 | "GET http://test/http HTTP/1.1\r\n" |
| 4627 | "Host: test\r\n" |
| 4628 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4629 | }; |
| 4630 | MockRead http_reads[] = { |
| 4631 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4632 | "Proxy-Connection: keep-alive\r\n" |
| 4633 | "Content-Length: 13\r\n\r\n" |
| 4634 | "HTTP Response"), |
| 4635 | }; |
| 4636 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 4637 | http_writes, arraysize(http_writes)); |
| 4638 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 4639 | |
| 4640 | MockWrite https_writes[] = { |
| 4641 | MockWrite(SYNCHRONOUS, |
| 4642 | "GET http://test/https HTTP/1.1\r\n" |
| 4643 | "Host: test\r\n" |
| 4644 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4645 | }; |
| 4646 | MockRead https_reads[] = { |
| 4647 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4648 | "Proxy-Connection: keep-alive\r\n" |
| 4649 | "Content-Length: 14\r\n\r\n" |
| 4650 | "HTTPS Response"), |
| 4651 | }; |
| 4652 | StaticSocketDataProvider https_data(https_reads, arraysize(https_reads), |
| 4653 | https_writes, arraysize(https_writes)); |
| 4654 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 4655 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 4656 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4657 | |
| 4658 | struct TestCase { |
| 4659 | GURL url; |
| 4660 | std::string expected_response; |
| 4661 | // How many idle sockets there should be in the SOCKS proxy socket pool |
| 4662 | // after the test. |
| 4663 | int expected_idle_socks_sockets; |
| 4664 | // How many idle sockets there should be in the HTTP proxy socket pool after |
| 4665 | // the test. |
| 4666 | int expected_idle_http_sockets; |
| 4667 | } const kTestCases[] = { |
| 4668 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0}, |
| 4669 | {GURL("http://test/socks5"), "SOCKS5 Response", 2, 0}, |
| 4670 | {GURL("http://test/http"), "HTTP Response", 2, 1}, |
| 4671 | {GURL("http://test/https"), "HTTPS Response", 2, 2}, |
| 4672 | }; |
| 4673 | |
| 4674 | for (const auto& test_case : kTestCases) { |
| 4675 | HttpRequestInfo request; |
| 4676 | request.method = "GET"; |
| 4677 | request.url = test_case.url; |
| 4678 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 4679 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 4680 | session.get()); |
| 4681 | TestCompletionCallback callback; |
| 4682 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4683 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4684 | |
| 4685 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4686 | ASSERT_TRUE(response); |
| 4687 | ASSERT_TRUE(response->headers); |
| 4688 | EXPECT_EQ(200, response->headers->response_code()); |
| 4689 | std::string response_data; |
| 4690 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4691 | EXPECT_EQ(test_case.expected_response, response_data); |
| 4692 | |
| 4693 | // Return the socket to the socket pool, so can make sure it's not used for |
| 4694 | // the next requests. |
| 4695 | trans.reset(); |
| 4696 | base::RunLoop().RunUntilIdle(); |
| 4697 | |
| 4698 | // Check the number of idle sockets in the pool, to make sure that used |
| 4699 | // sockets are indeed being returned to the socket pool. If each request |
| 4700 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 4701 | // pass. |
| 4702 | EXPECT_EQ( |
| 4703 | test_case.expected_idle_socks_sockets, |
| 4704 | session |
| 4705 | ->GetSocketPoolForSOCKSProxy( |
| 4706 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4707 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4708 | ->IdleSocketCount()); |
| 4709 | EXPECT_EQ( |
| 4710 | test_case.expected_idle_http_sockets, |
| 4711 | session |
| 4712 | ->GetSocketPoolForHTTPProxy( |
| 4713 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4714 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4715 | ->IdleSocketCount()); |
| 4716 | } |
| 4717 | } |
| 4718 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4719 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4720 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4721 | HttpRequestInfo request1; |
| 4722 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4723 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4724 | |
| 4725 | HttpRequestInfo request2; |
| 4726 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4727 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4728 | |
| 4729 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 4730 | session_deps_.proxy_resolution_service = |
| 4731 | ProxyResolutionService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4732 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4733 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4734 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4735 | |
| 4736 | // Since we have proxy, should try to establish tunnel. |
| 4737 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4738 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4739 | "Host: www.example.org:443\r\n" |
| 4740 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4741 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4742 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4743 | "Host: www.example.org\r\n" |
| 4744 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4745 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4746 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4747 | "Host: www.example.org\r\n" |
| 4748 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4749 | }; |
| 4750 | |
| 4751 | // The proxy responds to the connect with a 407, using a persistent |
| 4752 | // connection. |
| 4753 | MockRead data_reads1[] = { |
| 4754 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4755 | |
| 4756 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4757 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4758 | MockRead(SYNCHRONOUS, "1"), |
| 4759 | |
| 4760 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4761 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4762 | MockRead(SYNCHRONOUS, "22"), |
| 4763 | }; |
| 4764 | |
| 4765 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4766 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4767 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4768 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4770 | |
| 4771 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4772 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4773 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4774 | |
| 4775 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4776 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4777 | |
| 4778 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4779 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4780 | |
| 4781 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4782 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4783 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4784 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4785 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4786 | |
| 4787 | LoadTimingInfo load_timing_info1; |
| 4788 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4789 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4790 | |
| 4791 | trans1.reset(); |
| 4792 | |
| 4793 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4794 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4795 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4796 | |
| 4797 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4799 | |
| 4800 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4801 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4802 | |
| 4803 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4804 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4805 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4806 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4807 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4808 | |
| 4809 | LoadTimingInfo load_timing_info2; |
| 4810 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4811 | TestLoadTimingReused(load_timing_info2); |
| 4812 | |
| 4813 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4814 | |
| 4815 | trans2.reset(); |
| 4816 | session->CloseAllConnections(); |
| 4817 | } |
| 4818 | |
| 4819 | // 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] | 4820 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4821 | HttpRequestInfo request1; |
| 4822 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4823 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4824 | |
| 4825 | HttpRequestInfo request2; |
| 4826 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4827 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4828 | |
| 4829 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 4830 | session_deps_.proxy_resolution_service = |
| 4831 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4832 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4833 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4835 | |
| 4836 | // Since we have proxy, should try to establish tunnel. |
| 4837 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4838 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4839 | "Host: www.example.org:443\r\n" |
| 4840 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4841 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4842 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4843 | "Host: www.example.org\r\n" |
| 4844 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4845 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4846 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4847 | "Host: www.example.org\r\n" |
| 4848 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4849 | }; |
| 4850 | |
| 4851 | // The proxy responds to the connect with a 407, using a persistent |
| 4852 | // connection. |
| 4853 | MockRead data_reads1[] = { |
| 4854 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4855 | |
| 4856 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4857 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4858 | MockRead(SYNCHRONOUS, "1"), |
| 4859 | |
| 4860 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4861 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4862 | MockRead(SYNCHRONOUS, "22"), |
| 4863 | }; |
| 4864 | |
| 4865 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4866 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4867 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4868 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4869 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4870 | |
| 4871 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4872 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4873 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4874 | |
| 4875 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4876 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4877 | |
| 4878 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4879 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4880 | |
| 4881 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4882 | ASSERT_TRUE(response1); |
| 4883 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4884 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4885 | |
| 4886 | LoadTimingInfo load_timing_info1; |
| 4887 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4888 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4889 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4890 | |
| 4891 | trans1.reset(); |
| 4892 | |
| 4893 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4894 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4895 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4896 | |
| 4897 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4898 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4899 | |
| 4900 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4901 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4902 | |
| 4903 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4904 | ASSERT_TRUE(response2); |
| 4905 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4906 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4907 | |
| 4908 | LoadTimingInfo load_timing_info2; |
| 4909 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4910 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4911 | |
| 4912 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4913 | |
| 4914 | trans2.reset(); |
| 4915 | session->CloseAllConnections(); |
| 4916 | } |
| 4917 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4918 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4919 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4920 | HttpRequestInfo request; |
| 4921 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4922 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4923 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4924 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 4925 | session_deps_.proxy_resolution_service = |
| 4926 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4927 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4928 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4929 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4930 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4931 | // Since we have proxy, should use full url |
| 4932 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4933 | MockWrite( |
| 4934 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4935 | "Host: www.example.org\r\n" |
| 4936 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4937 | }; |
| 4938 | |
| 4939 | MockRead data_reads1[] = { |
| 4940 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4941 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4942 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4943 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4944 | }; |
| 4945 | |
| 4946 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4947 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4948 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4949 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4950 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4951 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4952 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4953 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4954 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4955 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4956 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4957 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4958 | |
| 4959 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4960 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4961 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4962 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4963 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4964 | TestLoadTimingNotReused(load_timing_info, |
| 4965 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4966 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4967 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4968 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4969 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4970 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4971 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4972 | EXPECT_EQ(200, response->headers->response_code()); |
| 4973 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4974 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4975 | |
| 4976 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4977 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4978 | } |
| 4979 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4980 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4981 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4982 | HttpRequestInfo request; |
| 4983 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4984 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4985 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4986 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 4987 | session_deps_.proxy_resolution_service = |
| 4988 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4989 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4990 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4991 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4992 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4993 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4994 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4995 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4996 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4997 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4998 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4999 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5000 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5001 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5002 | }; |
| 5003 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5004 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5005 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5006 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5007 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5008 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5009 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5010 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5011 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5012 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5013 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5014 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5015 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5016 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5017 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5018 | |
| 5019 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5020 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5021 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5022 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5023 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5024 | TestLoadTimingNotReused(load_timing_info, |
| 5025 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5026 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5027 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5028 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5029 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5030 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5031 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5032 | |
| 5033 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5034 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5035 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5036 | } |
| 5037 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5038 | // Verifies that a session which races and wins against the owning transaction |
| 5039 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5040 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5041 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5042 | HttpRequestInfo request; |
| 5043 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5044 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5045 | |
| 5046 | // Configure SPDY proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 5047 | session_deps_.proxy_resolution_service = |
| 5048 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5049 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5050 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5051 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5052 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5053 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5054 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5055 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5056 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5057 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5058 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5059 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5060 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5061 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5062 | }; |
| 5063 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5064 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5065 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5066 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5067 | |
| 5068 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5069 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5070 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5071 | |
| 5072 | TestCompletionCallback callback1; |
| 5073 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5074 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5075 | |
| 5076 | // Stall the hostname resolution begun by the transaction. |
| 5077 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 5078 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5079 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5080 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5081 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5082 | |
| 5083 | // Race a session to the proxy, which completes first. |
| 5084 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5085 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
| 5086 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5087 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5088 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5089 | |
| 5090 | // Unstall the resolution begun by the transaction. |
| 5091 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5092 | session_deps_.host_resolver->ResolveAllPending(); |
| 5093 | |
| 5094 | EXPECT_FALSE(callback1.have_result()); |
| 5095 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5096 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5097 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5098 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5099 | ASSERT_TRUE(response); |
| 5100 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5101 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5102 | |
| 5103 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5104 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5105 | EXPECT_EQ(kUploadData, response_data); |
| 5106 | } |
| 5107 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5108 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5109 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5110 | HttpRequestInfo request; |
| 5111 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5112 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5113 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5114 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 5115 | session_deps_.proxy_resolution_service = |
| 5116 | ProxyResolutionService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5117 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5118 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5119 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5120 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5121 | // The first request will be a bare GET, the second request will be a |
| 5122 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5123 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5124 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5125 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5126 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5127 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5128 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5129 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5130 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 5131 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 5132 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5133 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5134 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5135 | }; |
| 5136 | |
| 5137 | // The first response is a 407 proxy authentication challenge, and the second |
| 5138 | // response will be a 200 response since the second request includes a valid |
| 5139 | // Authorization header. |
| 5140 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5141 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5142 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5143 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 5144 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5145 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 5146 | SpdySerializedFrame body_authentication( |
| 5147 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5148 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5149 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5150 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5151 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5152 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5153 | CreateMockRead(resp_data, 4), |
| 5154 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5155 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5156 | }; |
| 5157 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5158 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5159 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5160 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5161 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5162 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5163 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5165 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5166 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5167 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5168 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5169 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5170 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5171 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5172 | |
| 5173 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5174 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5176 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5177 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5178 | ASSERT_TRUE(response); |
| 5179 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5180 | EXPECT_EQ(407, response->headers->response_code()); |
| 5181 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5182 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5183 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5184 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5186 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5187 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5188 | |
| 5189 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5190 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5192 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5193 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5194 | ASSERT_TRUE(response_restart); |
| 5195 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5196 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5197 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5198 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5199 | } |
| 5200 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5201 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5202 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5203 | HttpRequestInfo request; |
| 5204 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5205 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5206 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5207 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 5208 | session_deps_.proxy_resolution_service = |
| 5209 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5210 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5211 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5212 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5213 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5214 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5215 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5216 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5217 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5218 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5219 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5220 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5221 | const char get[] = |
| 5222 | "GET / HTTP/1.1\r\n" |
| 5223 | "Host: www.example.org\r\n" |
| 5224 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5225 | SpdySerializedFrame wrapped_get( |
| 5226 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5227 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5228 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5229 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5230 | SpdySerializedFrame wrapped_get_resp( |
| 5231 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 5232 | SpdySerializedFrame wrapped_body( |
| 5233 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 5234 | SpdySerializedFrame window_update( |
| 5235 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5236 | |
| 5237 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5238 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5239 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5240 | }; |
| 5241 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5242 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5243 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5244 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5245 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5246 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5247 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5248 | }; |
| 5249 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5250 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5251 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5252 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5253 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5254 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5255 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5256 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5257 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5258 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5260 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5261 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5262 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5263 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5264 | |
| 5265 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5266 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5267 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5268 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5269 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5270 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5272 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5273 | ASSERT_TRUE(response); |
| 5274 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5275 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5276 | |
| 5277 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5278 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5279 | EXPECT_EQ("1234567890", response_data); |
| 5280 | } |
| 5281 | |
| 5282 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5283 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5284 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5285 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5286 | HttpRequestInfo request; |
| 5287 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5288 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5289 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5290 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 5291 | session_deps_.proxy_resolution_service = |
| 5292 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5293 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5294 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5295 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5296 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5297 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5298 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5299 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5300 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5301 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5302 | // fetch https://www.example.org/ via SPDY |
| 5303 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5304 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5305 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5306 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5307 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5308 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5309 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5310 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5311 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5312 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5313 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5314 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5315 | SpdySerializedFrame window_update_get_resp( |
| 5316 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 5317 | SpdySerializedFrame window_update_body( |
| 5318 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5319 | |
| 5320 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5321 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5322 | CreateMockWrite(window_update_get_resp, 6), |
| 5323 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5324 | }; |
| 5325 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5326 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5327 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5328 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5329 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5330 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5331 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5332 | }; |
| 5333 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5334 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5335 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5336 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5337 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5338 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5339 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5340 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5341 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5342 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5343 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5345 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5346 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5347 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5348 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5349 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5350 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5351 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5352 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5353 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5354 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5355 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5356 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5357 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5358 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5359 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5360 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5361 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5362 | ASSERT_TRUE(response); |
| 5363 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5364 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5365 | |
| 5366 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5367 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5368 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5369 | } |
| 5370 | |
| 5371 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5372 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5373 | HttpRequestInfo request; |
| 5374 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5375 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5376 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5377 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 5378 | session_deps_.proxy_resolution_service = |
| 5379 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5380 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5381 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5382 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5383 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5384 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5385 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5386 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5387 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5388 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5389 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5390 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5391 | |
| 5392 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5393 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5394 | }; |
| 5395 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5396 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5397 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5398 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5399 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5400 | }; |
| 5401 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5402 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5403 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5404 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5405 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5406 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5407 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5408 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5409 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5410 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5411 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5412 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5413 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5415 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5416 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5417 | |
| 5418 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5419 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5420 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5421 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5422 | } |
| 5423 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5424 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5425 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5426 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5427 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5428 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 5429 | session_deps_.proxy_resolution_service = |
| 5430 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5431 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5432 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5433 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5434 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5435 | |
| 5436 | HttpRequestInfo request1; |
| 5437 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5438 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5439 | request1.load_flags = 0; |
| 5440 | |
| 5441 | HttpRequestInfo request2; |
| 5442 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5443 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5444 | request2.load_flags = 0; |
| 5445 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5446 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5447 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5448 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5449 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5450 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5451 | // Fetch https://www.example.org/ via HTTP. |
| 5452 | const char get1[] = |
| 5453 | "GET / HTTP/1.1\r\n" |
| 5454 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5455 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5456 | SpdySerializedFrame wrapped_get1( |
| 5457 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5458 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5459 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5460 | SpdySerializedFrame wrapped_get_resp1( |
| 5461 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5462 | SpdySerializedFrame wrapped_body1( |
| 5463 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5464 | SpdySerializedFrame window_update( |
| 5465 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5466 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5467 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5468 | SpdyHeaderBlock connect2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 5469 | connect2_block[kHttp2MethodHeader] = "CONNECT"; |
| 5470 | connect2_block[kHttp2AuthorityHeader] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5471 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5472 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5473 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5474 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5475 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5476 | // Fetch https://mail.example.org/ via HTTP. |
| 5477 | const char get2[] = |
| 5478 | "GET / HTTP/1.1\r\n" |
| 5479 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5480 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5481 | SpdySerializedFrame wrapped_get2( |
| 5482 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5483 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5484 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5485 | SpdySerializedFrame wrapped_get_resp2( |
| 5486 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5487 | SpdySerializedFrame wrapped_body2( |
| 5488 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5489 | |
| 5490 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5491 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5492 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5493 | }; |
| 5494 | |
| 5495 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5496 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5497 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5498 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5499 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5500 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5501 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5502 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5503 | }; |
| 5504 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5505 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5506 | arraysize(spdy_writes)); |
| 5507 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5508 | |
| 5509 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5510 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5511 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5512 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5513 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5514 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5515 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5516 | |
| 5517 | TestCompletionCallback callback; |
| 5518 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5519 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5520 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5521 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5522 | |
| 5523 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5524 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5525 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5526 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5527 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5528 | ASSERT_TRUE(response); |
| 5529 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5530 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5531 | |
| 5532 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5533 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5534 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5535 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5537 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5538 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5539 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5540 | |
| 5541 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5542 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5543 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5544 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5545 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5546 | |
| 5547 | // The requests should have different IDs, since they each are using their own |
| 5548 | // separate stream. |
| 5549 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5551 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5552 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5556 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5557 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5558 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5559 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 5560 | session_deps_.proxy_resolution_service = |
| 5561 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5562 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5563 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5564 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5565 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5566 | |
| 5567 | HttpRequestInfo request1; |
| 5568 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5569 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5570 | request1.load_flags = 0; |
| 5571 | |
| 5572 | HttpRequestInfo request2; |
| 5573 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5574 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5575 | request2.load_flags = 0; |
| 5576 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5577 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5578 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5579 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5580 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5581 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5582 | // Fetch https://www.example.org/ via HTTP. |
| 5583 | const char get1[] = |
| 5584 | "GET / HTTP/1.1\r\n" |
| 5585 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5586 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5587 | SpdySerializedFrame wrapped_get1( |
| 5588 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5589 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5590 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5591 | SpdySerializedFrame wrapped_get_resp1( |
| 5592 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5593 | SpdySerializedFrame wrapped_body1( |
| 5594 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5595 | SpdySerializedFrame window_update( |
| 5596 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5597 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5598 | // Fetch https://www.example.org/2 via HTTP. |
| 5599 | const char get2[] = |
| 5600 | "GET /2 HTTP/1.1\r\n" |
| 5601 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5602 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5603 | SpdySerializedFrame wrapped_get2( |
| 5604 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5605 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5606 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5607 | SpdySerializedFrame wrapped_get_resp2( |
| 5608 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5609 | SpdySerializedFrame wrapped_body2( |
| 5610 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5611 | |
| 5612 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5613 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5614 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5615 | }; |
| 5616 | |
| 5617 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5618 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5619 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5620 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5621 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5622 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5623 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5624 | }; |
| 5625 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5626 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5627 | arraysize(spdy_writes)); |
| 5628 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5629 | |
| 5630 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5631 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5632 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5633 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5634 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5635 | |
| 5636 | TestCompletionCallback callback; |
| 5637 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5638 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5639 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5640 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5642 | |
| 5643 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5644 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5645 | |
| 5646 | LoadTimingInfo load_timing_info; |
| 5647 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5648 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5649 | |
| 5650 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5651 | ASSERT_TRUE(response); |
| 5652 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5653 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5654 | |
| 5655 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5656 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5657 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5658 | trans.reset(); |
| 5659 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5660 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5661 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5662 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5663 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5664 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5665 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5666 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5667 | |
| 5668 | LoadTimingInfo load_timing_info2; |
| 5669 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5670 | TestLoadTimingReused(load_timing_info2); |
| 5671 | |
| 5672 | // The requests should have the same ID. |
| 5673 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5674 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5675 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5676 | } |
| 5677 | |
| 5678 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5679 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5680 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5681 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 5682 | session_deps_.proxy_resolution_service = |
| 5683 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5684 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5685 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5686 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5687 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5688 | |
| 5689 | HttpRequestInfo request1; |
| 5690 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5691 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5692 | request1.load_flags = 0; |
| 5693 | |
| 5694 | HttpRequestInfo request2; |
| 5695 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5696 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5697 | request2.load_flags = 0; |
| 5698 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5699 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5700 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5701 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5702 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5703 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5704 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5705 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5706 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5707 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5708 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5709 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5710 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5711 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5712 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5713 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5714 | SpdySerializedFrame body2( |
| 5715 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5716 | |
| 5717 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5718 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5719 | }; |
| 5720 | |
| 5721 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5722 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5723 | CreateMockRead(body1, 2, ASYNC), |
| 5724 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5725 | CreateMockRead(body2, 5, ASYNC), |
| 5726 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5727 | }; |
| 5728 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5729 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5730 | arraysize(spdy_writes)); |
| 5731 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5732 | |
| 5733 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5734 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5735 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5736 | |
| 5737 | TestCompletionCallback callback; |
| 5738 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5739 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5740 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5741 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5742 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5743 | |
| 5744 | LoadTimingInfo load_timing_info; |
| 5745 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5746 | TestLoadTimingNotReused(load_timing_info, |
| 5747 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5748 | |
| 5749 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5750 | ASSERT_TRUE(response); |
| 5751 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5752 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5753 | |
| 5754 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5755 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5756 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5757 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5758 | // Delete the first request, so the second one can reuse the socket. |
| 5759 | trans.reset(); |
| 5760 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5761 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5762 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5763 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5764 | |
| 5765 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5766 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5767 | TestLoadTimingReused(load_timing_info2); |
| 5768 | |
| 5769 | // The requests should have the same ID. |
| 5770 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5771 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5772 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5773 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5774 | } |
| 5775 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5776 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5777 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5778 | HttpRequestInfo request; |
| 5779 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5780 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5781 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5782 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5783 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5784 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 5785 | session_deps_.proxy_resolution_service = |
| 5786 | ProxyResolutionService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5787 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5788 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5789 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5790 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5791 | // Since we have proxy, should use full url |
| 5792 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5793 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5794 | "Host: www.example.org\r\n" |
| 5795 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5796 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5797 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5798 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5799 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5800 | "Host: www.example.org\r\n" |
| 5801 | "Proxy-Connection: keep-alive\r\n" |
| 5802 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5803 | }; |
| 5804 | |
| 5805 | // The proxy responds to the GET with a 407, using a persistent |
| 5806 | // connection. |
| 5807 | MockRead data_reads1[] = { |
| 5808 | // No credentials. |
| 5809 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5810 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5811 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5812 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5813 | |
| 5814 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5815 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5816 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5817 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5818 | }; |
| 5819 | |
| 5820 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5821 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5822 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5823 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5824 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5825 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5826 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5827 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5828 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5829 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5830 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5831 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5832 | |
| 5833 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5834 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5835 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5836 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5837 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5838 | TestLoadTimingNotReused(load_timing_info, |
| 5839 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5840 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5841 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5842 | ASSERT_TRUE(response); |
| 5843 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5844 | EXPECT_EQ(407, response->headers->response_code()); |
| 5845 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5846 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5847 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5848 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5849 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5850 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5851 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5852 | |
| 5853 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5854 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5855 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5856 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5857 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5858 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5859 | TestLoadTimingReused(load_timing_info); |
| 5860 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5861 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5862 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5863 | |
| 5864 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5865 | EXPECT_EQ(200, response->headers->response_code()); |
| 5866 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5867 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5868 | |
| 5869 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5870 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5871 | } |
| 5872 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5873 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5874 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5875 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5876 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5877 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5878 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5879 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 5880 | session_deps_.proxy_resolution_service = |
| 5881 | ProxyResolutionService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5882 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5883 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5884 | // Since we have proxy, should try to establish tunnel. |
| 5885 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5886 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5887 | "Host: www.example.org:443\r\n" |
| 5888 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5889 | }; |
| 5890 | |
| 5891 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5892 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5893 | // No response body because the test stops reading here. |
| 5894 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5895 | }; |
| 5896 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5897 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5898 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5899 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5900 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5901 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5902 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5903 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5904 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5905 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5907 | |
| 5908 | rv = callback.WaitForResult(); |
| 5909 | EXPECT_EQ(expected_status, rv); |
| 5910 | } |
| 5911 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5912 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5913 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5914 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5915 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5916 | } |
| 5917 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5918 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5919 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5920 | } |
| 5921 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5922 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5923 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5924 | } |
| 5925 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5926 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5927 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5928 | } |
| 5929 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5930 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5931 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5932 | } |
| 5933 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5934 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5935 | ConnectStatusHelper( |
| 5936 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5937 | } |
| 5938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5939 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5940 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5941 | } |
| 5942 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5943 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5944 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5945 | } |
| 5946 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5947 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5948 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5949 | } |
| 5950 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5951 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5952 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5953 | } |
| 5954 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5955 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5956 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5957 | } |
| 5958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5959 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5960 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5961 | } |
| 5962 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5963 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5964 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5965 | } |
| 5966 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5967 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5968 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5969 | } |
| 5970 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5971 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5972 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5973 | } |
| 5974 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5975 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5976 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5977 | } |
| 5978 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5979 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5980 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5981 | } |
| 5982 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5983 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5984 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5985 | } |
| 5986 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5987 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5988 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5989 | } |
| 5990 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5991 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5992 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5993 | } |
| 5994 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5995 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5996 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5997 | } |
| 5998 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5999 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6000 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6001 | } |
| 6002 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6003 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6004 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6005 | } |
| 6006 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6007 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6008 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6009 | } |
| 6010 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6011 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6012 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6013 | } |
| 6014 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6015 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6016 | ConnectStatusHelperWithExpectedStatus( |
| 6017 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6018 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6019 | } |
| 6020 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6021 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6022 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6023 | } |
| 6024 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6025 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6026 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6027 | } |
| 6028 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6029 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6030 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6031 | } |
| 6032 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6033 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6034 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6035 | } |
| 6036 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6037 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6038 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6039 | } |
| 6040 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6041 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6042 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6043 | } |
| 6044 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6045 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6046 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6047 | } |
| 6048 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6049 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6050 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6051 | } |
| 6052 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6053 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6054 | ConnectStatusHelper( |
| 6055 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6056 | } |
| 6057 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6058 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6059 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6060 | } |
| 6061 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6062 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6063 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6064 | } |
| 6065 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6066 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6067 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6068 | } |
| 6069 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6070 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6071 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6072 | } |
| 6073 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6074 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6075 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6076 | } |
| 6077 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6078 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6079 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6080 | } |
| 6081 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6082 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6083 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6084 | } |
| 6085 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6086 | // Test the flow when both the proxy server AND origin server require |
| 6087 | // authentication. Again, this uses basic auth for both since that is |
| 6088 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6089 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6090 | HttpRequestInfo request; |
| 6091 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6092 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6093 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6094 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 6095 | session_deps_.proxy_resolution_service = |
| 6096 | ProxyResolutionService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6097 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6098 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6099 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6100 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6101 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6102 | MockWrite( |
| 6103 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6104 | "Host: www.example.org\r\n" |
| 6105 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6106 | }; |
| 6107 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6108 | MockRead data_reads1[] = { |
| 6109 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6110 | // Give a couple authenticate options (only the middle one is actually |
| 6111 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6112 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6113 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6114 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6115 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6116 | // Large content-length -- won't matter, as connection will be reset. |
| 6117 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6118 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6119 | }; |
| 6120 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6121 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6122 | // request we should be issuing -- the final header line contains the |
| 6123 | // proxy's credentials. |
| 6124 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6125 | MockWrite( |
| 6126 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6127 | "Host: www.example.org\r\n" |
| 6128 | "Proxy-Connection: keep-alive\r\n" |
| 6129 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6130 | }; |
| 6131 | |
| 6132 | // Now the proxy server lets the request pass through to origin server. |
| 6133 | // The origin server responds with a 401. |
| 6134 | MockRead data_reads2[] = { |
| 6135 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6136 | // Note: We are using the same realm-name as the proxy server. This is |
| 6137 | // completely valid, as realms are unique across hosts. |
| 6138 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6139 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6140 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6141 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6142 | }; |
| 6143 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6144 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6145 | // the credentials for both the proxy and origin server. |
| 6146 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6147 | MockWrite( |
| 6148 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6149 | "Host: www.example.org\r\n" |
| 6150 | "Proxy-Connection: keep-alive\r\n" |
| 6151 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 6152 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6153 | }; |
| 6154 | |
| 6155 | // Lastly we get the desired content. |
| 6156 | MockRead data_reads3[] = { |
| 6157 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6158 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6159 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6160 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6161 | }; |
| 6162 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6163 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6164 | data_writes1, arraysize(data_writes1)); |
| 6165 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6166 | data_writes2, arraysize(data_writes2)); |
| 6167 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6168 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6169 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6170 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6171 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6173 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6174 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6175 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6176 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6177 | |
| 6178 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6179 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6180 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6181 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6182 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6183 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6184 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6185 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6186 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6187 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6188 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6189 | |
| 6190 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6191 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6192 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6193 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6194 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6195 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6196 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6197 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6198 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6199 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 6200 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6201 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6202 | |
| 6203 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6204 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6205 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6206 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6207 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6208 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6209 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6210 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6211 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 6212 | // can't hook into its internals to cause it to generate predictable NTLM |
| 6213 | // authorization headers. |
| 6214 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6215 | // The NTLM authentication unit tests are based on known test data from the |
| 6216 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 6217 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 6218 | // for the implementation and testing of the protocol. |
| 6219 | // |
| 6220 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6221 | |
| 6222 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6223 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6224 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6225 | request.method = "GET"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6226 | request.url = GURL("https://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6227 | |
| 6228 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6229 | // to other auth schemes. |
| 6230 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6231 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6232 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6233 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6234 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6235 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6236 | // Generate the NTLM messages based on known test data. |
| 6237 | std::string negotiate_msg; |
| 6238 | std::string challenge_msg; |
| 6239 | std::string authenticate_msg; |
| 6240 | base::Base64Encode( |
| 6241 | base::StringPiece( |
| 6242 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6243 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6244 | &negotiate_msg); |
| 6245 | base::Base64Encode(base::StringPiece(reinterpret_cast<const char*>( |
| 6246 | ntlm::test::kChallengeMsgV1), |
| 6247 | arraysize(ntlm::test::kChallengeMsgV1)), |
| 6248 | &challenge_msg); |
| 6249 | base::Base64Encode( |
| 6250 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6251 | reinterpret_cast<const char*>( |
| 6252 | ntlm::test::kExpectedAuthenticateMsgSpecResponseV1), |
| 6253 | arraysize(ntlm::test::kExpectedAuthenticateMsgSpecResponseV1)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6254 | &authenticate_msg); |
| 6255 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6256 | MockWrite data_writes1[] = { |
| 6257 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6258 | "Host: 172.22.68.17\r\n" |
| 6259 | "Connection: keep-alive\r\n\r\n"), |
| 6260 | }; |
| 6261 | |
| 6262 | MockRead data_reads1[] = { |
| 6263 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6264 | // Negotiate and NTLM are often requested together. However, we only want |
| 6265 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6266 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6267 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6268 | MockRead("Connection: close\r\n"), |
| 6269 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6270 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6271 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6272 | }; |
| 6273 | |
| 6274 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6275 | // After restarting with a null identity, this is the |
| 6276 | // request we should be issuing -- the final header line contains a Type |
| 6277 | // 1 message. |
| 6278 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6279 | "Host: 172.22.68.17\r\n" |
| 6280 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6281 | "Authorization: NTLM "), |
| 6282 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6283 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6284 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6285 | // (using correct credentials). The second request continues on the |
| 6286 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6287 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6288 | "Host: 172.22.68.17\r\n" |
| 6289 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6290 | "Authorization: NTLM "), |
| 6291 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6292 | }; |
| 6293 | |
| 6294 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6295 | // The origin server responds with a Type 2 message. |
| 6296 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6297 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6298 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6299 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6300 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6301 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6302 | // Lastly we get the desired content. |
| 6303 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6304 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6305 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6306 | }; |
| 6307 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6308 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6309 | data_writes1, arraysize(data_writes1)); |
| 6310 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6311 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6312 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6313 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6314 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6315 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6316 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6317 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6318 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6319 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6320 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6321 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6322 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6323 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6324 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6325 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6326 | |
| 6327 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6328 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6329 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6330 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6331 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6332 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6333 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6334 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6335 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6336 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6337 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6338 | rv = trans.RestartWithAuth( |
| 6339 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6340 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6342 | |
| 6343 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6344 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6345 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6346 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6347 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6348 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6349 | ASSERT_TRUE(response); |
| 6350 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6352 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6353 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6354 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6356 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6357 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6358 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6359 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6360 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6361 | ASSERT_TRUE(response); |
| 6362 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6363 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6364 | |
| 6365 | std::string response_data; |
| 6366 | rv = ReadTransaction(&trans, &response_data); |
| 6367 | EXPECT_THAT(rv, IsOk()); |
| 6368 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6369 | |
| 6370 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6371 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6372 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6373 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6374 | } |
| 6375 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6376 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6377 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV1WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6378 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6379 | request.method = "GET"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6380 | request.url = GURL("https://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6381 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6382 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6383 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6384 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6385 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6386 | // Generate the NTLM messages based on known test data. |
| 6387 | std::string negotiate_msg; |
| 6388 | std::string challenge_msg; |
| 6389 | std::string authenticate_msg; |
| 6390 | base::Base64Encode( |
| 6391 | base::StringPiece( |
| 6392 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6393 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6394 | &negotiate_msg); |
| 6395 | base::Base64Encode(base::StringPiece(reinterpret_cast<const char*>( |
| 6396 | ntlm::test::kChallengeMsgV1), |
| 6397 | arraysize(ntlm::test::kChallengeMsgV1)), |
| 6398 | &challenge_msg); |
| 6399 | base::Base64Encode( |
| 6400 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6401 | reinterpret_cast<const char*>( |
| 6402 | ntlm::test::kExpectedAuthenticateMsgSpecResponseV1), |
| 6403 | arraysize(ntlm::test::kExpectedAuthenticateMsgSpecResponseV1)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6404 | &authenticate_msg); |
| 6405 | |
| 6406 | // The authenticate message when |kWrongPassword| is sent. |
| 6407 | std::string wrong_password_authenticate_msg( |
| 6408 | "TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAAwADABwAAAACAAIAHwAAAAQABAAhAAAAAAA" |
| 6409 | "AABAAAAAA4IIAKqqqqqqqqqqAAAAAAAAAAAAAAAAAAAAAF2npafgDxlql9qxEIhLlsuuJIEd" |
| 6410 | "NQHk7kQAbwBtAGEAaQBuAFUAcwBlAHIAQwBPAE0AUABVAFQARQBSAA=="); |
| 6411 | |
| 6412 | // Sanity check that this is the same as |authenticate_msg| except for the |
| 6413 | // 24 bytes (32 encoded chars) of the NTLM Response. |
| 6414 | ASSERT_EQ(authenticate_msg.length(), |
| 6415 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6416 | ASSERT_EQ(authenticate_msg.length(), 200u); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6417 | ASSERT_EQ(base::StringPiece(authenticate_msg.data(), 117), |
| 6418 | base::StringPiece(wrong_password_authenticate_msg.data(), 117)); |
| 6419 | ASSERT_EQ( |
| 6420 | base::StringPiece(authenticate_msg.data() + 149, 51), |
| 6421 | base::StringPiece(wrong_password_authenticate_msg.data() + 149, 51)); |
| 6422 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6423 | MockWrite data_writes1[] = { |
| 6424 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6425 | "Host: 172.22.68.17\r\n" |
| 6426 | "Connection: keep-alive\r\n\r\n"), |
| 6427 | }; |
| 6428 | |
| 6429 | MockRead data_reads1[] = { |
| 6430 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6431 | // Negotiate and NTLM are often requested together. However, we only want |
| 6432 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6433 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6434 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6435 | MockRead("Connection: close\r\n"), |
| 6436 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6437 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6438 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6439 | }; |
| 6440 | |
| 6441 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6442 | // After restarting with a null identity, this is the |
| 6443 | // request we should be issuing -- the final header line contains a Type |
| 6444 | // 1 message. |
| 6445 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6446 | "Host: 172.22.68.17\r\n" |
| 6447 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6448 | "Authorization: NTLM "), |
| 6449 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6450 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6451 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6452 | // (using incorrect credentials). The second request continues on the |
| 6453 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6454 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6455 | "Host: 172.22.68.17\r\n" |
| 6456 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6457 | "Authorization: NTLM "), |
| 6458 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6459 | }; |
| 6460 | |
| 6461 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6462 | // The origin server responds with a Type 2 message. |
| 6463 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6464 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6465 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 6466 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6467 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6468 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6469 | // Wrong password. |
| 6470 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6471 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 6472 | MockRead("Content-Length: 42\r\n"), |
| 6473 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6474 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6475 | }; |
| 6476 | |
| 6477 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6478 | // After restarting with a null identity, this is the |
| 6479 | // request we should be issuing -- the final header line contains a Type |
| 6480 | // 1 message. |
| 6481 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6482 | "Host: 172.22.68.17\r\n" |
| 6483 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6484 | "Authorization: NTLM "), |
| 6485 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6487 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6488 | // (the credentials for the origin server). The second request continues |
| 6489 | // on the same connection. |
| 6490 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6491 | "Host: 172.22.68.17\r\n" |
| 6492 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6493 | "Authorization: NTLM "), |
| 6494 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6495 | }; |
| 6496 | |
| 6497 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6498 | // The origin server responds with a Type 2 message. |
| 6499 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6500 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6501 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6502 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6503 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6504 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6505 | // Lastly we get the desired content. |
| 6506 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6507 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6508 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6509 | }; |
| 6510 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6511 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6512 | data_writes1, arraysize(data_writes1)); |
| 6513 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6514 | data_writes2, arraysize(data_writes2)); |
| 6515 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6516 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6517 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6518 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6519 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6520 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6521 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6522 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6523 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6524 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6525 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6526 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6527 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6528 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6529 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6530 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6531 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6532 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6533 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6534 | |
| 6535 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6536 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6538 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6539 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6540 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6541 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6542 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6543 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6544 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6545 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6546 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6547 | rv = trans.RestartWithAuth( |
| 6548 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 6549 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6550 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6551 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6552 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6553 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6555 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6556 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6557 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6558 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6559 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6560 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6561 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6562 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6563 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6564 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6565 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6566 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6567 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6568 | |
| 6569 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6570 | rv = trans.RestartWithAuth( |
| 6571 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6572 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6573 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6574 | |
| 6575 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6576 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6577 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6578 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6579 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6580 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6581 | |
| 6582 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6583 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6584 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6585 | |
| 6586 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6587 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6588 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6589 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6590 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6591 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6592 | |
| 6593 | std::string response_data; |
| 6594 | rv = ReadTransaction(&trans, &response_data); |
| 6595 | EXPECT_THAT(rv, IsOk()); |
| 6596 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6597 | |
| 6598 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6599 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6600 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6601 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6602 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6603 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6604 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6605 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6606 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 6607 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6608 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6609 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6610 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6611 | |
| 6612 | const char* kUrl = "https://172.22.68.17/kids/login.aspx"; |
| 6613 | |
| 6614 | HttpRequestInfo request; |
| 6615 | request.method = "GET"; |
| 6616 | request.url = GURL(kUrl); |
| 6617 | |
| 6618 | // First request without credentials. |
| 6619 | SpdyHeaderBlock request_headers0(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6620 | SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
| 6621 | 1, std::move(request_headers0), LOWEST, true)); |
| 6622 | |
| 6623 | SpdyHeaderBlock response_headers0; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 6624 | response_headers0[kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6625 | response_headers0["www-authenticate"] = "NTLM"; |
| 6626 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
| 6627 | 1, std::move(response_headers0), true)); |
| 6628 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6629 | // Stream 1 is closed. |
| 6630 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6631 | |
| 6632 | // Generate the NTLM messages based on known test data. |
| 6633 | std::string negotiate_msg; |
| 6634 | std::string challenge_msg; |
| 6635 | std::string authenticate_msg; |
| 6636 | base::Base64Encode( |
| 6637 | base::StringPiece( |
| 6638 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6639 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6640 | &negotiate_msg); |
| 6641 | base::Base64Encode(base::StringPiece(reinterpret_cast<const char*>( |
| 6642 | ntlm::test::kChallengeMsgV1), |
| 6643 | arraysize(ntlm::test::kChallengeMsgV1)), |
| 6644 | &challenge_msg); |
| 6645 | base::Base64Encode( |
| 6646 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6647 | reinterpret_cast<const char*>( |
| 6648 | ntlm::test::kExpectedAuthenticateMsgSpecResponseV1), |
| 6649 | arraysize(ntlm::test::kExpectedAuthenticateMsgSpecResponseV1)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6650 | &authenticate_msg); |
| 6651 | |
| 6652 | // Retry with authorization header. |
| 6653 | SpdyHeaderBlock request_headers1(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6654 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
| 6655 | SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
| 6656 | 3, std::move(request_headers1), LOWEST, true)); |
| 6657 | |
| 6658 | SpdySerializedFrame rst( |
| 6659 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_HTTP_1_1_REQUIRED)); |
| 6660 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6661 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 6662 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6663 | |
| 6664 | // Retry yet again using HTTP/1.1. |
| 6665 | MockWrite writes1[] = { |
| 6666 | // After restarting with a null identity, this is the |
| 6667 | // request we should be issuing -- the final header line contains a Type |
| 6668 | // 1 message. |
| 6669 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6670 | "Host: 172.22.68.17\r\n" |
| 6671 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6672 | "Authorization: NTLM "), |
| 6673 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6674 | |
| 6675 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6676 | // (the credentials for the origin server). The second request continues |
| 6677 | // on the same connection. |
| 6678 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6679 | "Host: 172.22.68.17\r\n" |
| 6680 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6681 | "Authorization: NTLM "), |
| 6682 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6683 | }; |
| 6684 | |
| 6685 | MockRead reads1[] = { |
| 6686 | // The origin server responds with a Type 2 message. |
| 6687 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6688 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6689 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6690 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6691 | MockRead("You are not authorized to view this page\r\n"), |
| 6692 | |
| 6693 | // Lastly we get the desired content. |
| 6694 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6695 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6696 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6697 | }; |
| 6698 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 6699 | arraysize(writes0)); |
| 6700 | StaticSocketDataProvider data1(reads1, arraysize(reads1), writes1, |
| 6701 | arraysize(writes1)); |
| 6702 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6703 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6704 | |
| 6705 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6706 | ssl0.next_proto = kProtoHTTP2; |
| 6707 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6708 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6709 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6710 | |
| 6711 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6712 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6713 | |
| 6714 | TestCompletionCallback callback1; |
| 6715 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6716 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6717 | |
| 6718 | rv = callback1.WaitForResult(); |
| 6719 | EXPECT_THAT(rv, IsOk()); |
| 6720 | |
| 6721 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6722 | |
| 6723 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6724 | ASSERT_TRUE(response); |
| 6725 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6726 | |
| 6727 | TestCompletionCallback callback2; |
| 6728 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6729 | rv = trans.RestartWithAuth( |
| 6730 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6731 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6732 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6733 | |
| 6734 | rv = callback2.WaitForResult(); |
| 6735 | EXPECT_THAT(rv, IsOk()); |
| 6736 | |
| 6737 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6738 | |
| 6739 | response = trans.GetResponseInfo(); |
| 6740 | ASSERT_TRUE(response); |
| 6741 | EXPECT_FALSE(response->auth_challenge); |
| 6742 | |
| 6743 | TestCompletionCallback callback3; |
| 6744 | |
| 6745 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6746 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6747 | |
| 6748 | rv = callback3.WaitForResult(); |
| 6749 | EXPECT_THAT(rv, IsOk()); |
| 6750 | |
| 6751 | response = trans.GetResponseInfo(); |
| 6752 | ASSERT_TRUE(response); |
| 6753 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6754 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6755 | |
| 6756 | std::string response_data; |
| 6757 | rv = ReadTransaction(&trans, &response_data); |
| 6758 | EXPECT_THAT(rv, IsOk()); |
| 6759 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6760 | |
| 6761 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6762 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6763 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6764 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6765 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6766 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6767 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6768 | // Test reading a server response which has only headers, and no body. |
| 6769 | // After some maximum number of bytes is consumed, the transaction should |
| 6770 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6771 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6772 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6773 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6774 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6775 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6778 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6779 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6780 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6781 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6782 | |
| 6783 | MockRead data_reads[] = { |
| 6784 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6785 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6786 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6787 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6788 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6789 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6790 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6792 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6793 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6794 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6795 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6796 | |
| 6797 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6798 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6799 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6800 | |
| 6801 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6802 | // establish tunnel. |
| 6803 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6804 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6805 | HttpRequestInfo request; |
| 6806 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6807 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6808 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6809 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 6810 | session_deps_.proxy_resolution_service = |
| 6811 | ProxyResolutionService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6812 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6813 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6814 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6815 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6816 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6817 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6818 | // Since we have proxy, should try to establish tunnel. |
| 6819 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6820 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6821 | "Host: www.example.org:443\r\n" |
| 6822 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6823 | }; |
| 6824 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6825 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6826 | // connection. Usually a proxy would return 501 (not implemented), |
| 6827 | // or 200 (tunnel established). |
| 6828 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6829 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6830 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6831 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6832 | }; |
| 6833 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6834 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6835 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6836 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6837 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6838 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6839 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6840 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6841 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6842 | |
| 6843 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6844 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6845 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6846 | // Empty the current queue. This is necessary because idle sockets are |
| 6847 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6848 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6849 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6850 | // We now check to make sure the TCPClientSocket was not added back to |
| 6851 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6852 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6853 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6854 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6855 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6856 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6857 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6858 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6859 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6860 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6861 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6862 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6863 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6864 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6865 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6866 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6867 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6868 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6869 | MockRead data_reads[] = { |
| 6870 | // A part of the response body is received with the response headers. |
| 6871 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6872 | // The rest of the response body is received in two parts. |
| 6873 | MockRead("lo"), |
| 6874 | MockRead(" world"), |
| 6875 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6876 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6877 | }; |
| 6878 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6879 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6880 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6881 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6882 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6883 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6884 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6885 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6886 | |
| 6887 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6888 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6889 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6890 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6891 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6892 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6893 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6894 | std::string status_line = response->headers->GetStatusLine(); |
| 6895 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6896 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6897 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6898 | |
| 6899 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6900 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6901 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6902 | EXPECT_EQ("hello world", response_data); |
| 6903 | |
| 6904 | // Empty the current queue. This is necessary because idle sockets are |
| 6905 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6906 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6907 | |
| 6908 | // 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] | 6909 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6910 | } |
| 6911 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6912 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6913 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6914 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6915 | HttpRequestInfo request; |
| 6916 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6917 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6918 | |
| 6919 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6920 | MockWrite( |
| 6921 | "GET / HTTP/1.1\r\n" |
| 6922 | "Host: www.example.org\r\n" |
| 6923 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6924 | }; |
| 6925 | |
| 6926 | MockRead data_reads[] = { |
| 6927 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6928 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6929 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6930 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6931 | }; |
| 6932 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6933 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6934 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6935 | |
| 6936 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6937 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6938 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6939 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6940 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6941 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6942 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6943 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6944 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6945 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6946 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6947 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6948 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6949 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6950 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6951 | ASSERT_TRUE(response); |
| 6952 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6953 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6954 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6955 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6956 | |
| 6957 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6958 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6959 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6960 | EXPECT_EQ("hello world", response_data); |
| 6961 | |
| 6962 | // Empty the current queue. This is necessary because idle sockets are |
| 6963 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6964 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6965 | |
| 6966 | // 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] | 6967 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6968 | } |
| 6969 | |
| 6970 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6971 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6972 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6973 | HttpRequestInfo request; |
| 6974 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6975 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6976 | |
| 6977 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6978 | MockWrite( |
| 6979 | "GET / HTTP/1.1\r\n" |
| 6980 | "Host: www.example.org\r\n" |
| 6981 | "Connection: keep-alive\r\n\r\n"), |
| 6982 | MockWrite( |
| 6983 | "GET / HTTP/1.1\r\n" |
| 6984 | "Host: www.example.org\r\n" |
| 6985 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6986 | }; |
| 6987 | |
| 6988 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6989 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6990 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6991 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6992 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6993 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6994 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6996 | |
| 6997 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6998 | data_writes, arraysize(data_writes)); |
| 6999 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 7000 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7001 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7002 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7003 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7004 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7005 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7006 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7007 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7008 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7009 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7010 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7011 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7012 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7013 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7014 | |
| 7015 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7016 | ASSERT_TRUE(response); |
| 7017 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7018 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7019 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7020 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7021 | |
| 7022 | std::string response_data; |
| 7023 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7024 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7025 | EXPECT_EQ("hello world", response_data); |
| 7026 | |
| 7027 | // Empty the current queue. This is necessary because idle sockets are |
| 7028 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7029 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7030 | |
| 7031 | // 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] | 7032 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7033 | |
| 7034 | // Now start the second transaction, which should reuse the previous socket. |
| 7035 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7036 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7037 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7038 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7039 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7040 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7041 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7042 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7043 | |
| 7044 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7045 | ASSERT_TRUE(response); |
| 7046 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7047 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7048 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7049 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7050 | |
| 7051 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7052 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7053 | EXPECT_EQ("hello world", response_data); |
| 7054 | |
| 7055 | // Empty the current queue. This is necessary because idle sockets are |
| 7056 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7057 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7058 | |
| 7059 | // 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] | 7060 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7061 | } |
| 7062 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7063 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7064 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7065 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7066 | HttpRequestInfo request; |
| 7067 | request.method = "GET"; |
| 7068 | request.url = GURL("http://www.example.org/"); |
| 7069 | request.load_flags = 0; |
| 7070 | |
| 7071 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7072 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7073 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7074 | |
| 7075 | MockRead data_reads[] = { |
| 7076 | // A part of the response body is received with the response headers. |
| 7077 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7078 | // The rest of the response body is received in two parts. |
| 7079 | MockRead("lo"), MockRead(" world"), |
| 7080 | MockRead("junk"), // Should not be read!! |
| 7081 | MockRead(SYNCHRONOUS, OK), |
| 7082 | }; |
| 7083 | |
| 7084 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7085 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7086 | |
| 7087 | TestCompletionCallback callback; |
| 7088 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7089 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7090 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7091 | |
| 7092 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7093 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7094 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7095 | ASSERT_TRUE(response); |
| 7096 | EXPECT_TRUE(response->headers); |
| 7097 | std::string status_line = response->headers->GetStatusLine(); |
| 7098 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7099 | |
| 7100 | // Make memory critical notification and ensure the transaction still has been |
| 7101 | // operating right. |
| 7102 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7103 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7104 | base::RunLoop().RunUntilIdle(); |
| 7105 | |
| 7106 | // Socket should not be flushed as long as it is not idle. |
| 7107 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7108 | |
| 7109 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7110 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7111 | EXPECT_THAT(rv, IsOk()); |
| 7112 | EXPECT_EQ("hello world", response_data); |
| 7113 | |
| 7114 | // Empty the current queue. This is necessary because idle sockets are |
| 7115 | // added to the connection pool asynchronously with a PostTask. |
| 7116 | base::RunLoop().RunUntilIdle(); |
| 7117 | |
| 7118 | // We now check to make sure the socket was added back to the pool. |
| 7119 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7120 | |
| 7121 | // Idle sockets should be flushed now. |
| 7122 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7123 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7124 | base::RunLoop().RunUntilIdle(); |
| 7125 | |
| 7126 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7127 | } |
| 7128 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7129 | // Disable idle socket closing on memory pressure. |
| 7130 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7131 | // low memory notification and ensure the socket pool is NOT flushed. |
| 7132 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 7133 | HttpRequestInfo request; |
| 7134 | request.method = "GET"; |
| 7135 | request.url = GURL("http://www.example.org/"); |
| 7136 | request.load_flags = 0; |
| 7137 | |
| 7138 | // Disable idle socket closing on memory pressure. |
| 7139 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 7140 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7141 | |
| 7142 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7143 | |
| 7144 | MockRead data_reads[] = { |
| 7145 | // A part of the response body is received with the response headers. |
| 7146 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7147 | // The rest of the response body is received in two parts. |
| 7148 | MockRead("lo"), MockRead(" world"), |
| 7149 | MockRead("junk"), // Should not be read!! |
| 7150 | MockRead(SYNCHRONOUS, OK), |
| 7151 | }; |
| 7152 | |
| 7153 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7154 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7155 | |
| 7156 | TestCompletionCallback callback; |
| 7157 | |
| 7158 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 7159 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7160 | |
| 7161 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7162 | |
| 7163 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7164 | ASSERT_TRUE(response); |
| 7165 | EXPECT_TRUE(response->headers); |
| 7166 | std::string status_line = response->headers->GetStatusLine(); |
| 7167 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7168 | |
| 7169 | // Make memory critical notification and ensure the transaction still has been |
| 7170 | // operating right. |
| 7171 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7172 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7173 | base::RunLoop().RunUntilIdle(); |
| 7174 | |
| 7175 | // Socket should not be flushed as long as it is not idle. |
| 7176 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7177 | |
| 7178 | std::string response_data; |
| 7179 | rv = ReadTransaction(&trans, &response_data); |
| 7180 | EXPECT_THAT(rv, IsOk()); |
| 7181 | EXPECT_EQ("hello world", response_data); |
| 7182 | |
| 7183 | // Empty the current queue. This is necessary because idle sockets are |
| 7184 | // added to the connection pool asynchronously with a PostTask. |
| 7185 | base::RunLoop().RunUntilIdle(); |
| 7186 | |
| 7187 | // We now check to make sure the socket was added back to the pool. |
| 7188 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7189 | |
| 7190 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 7191 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7192 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 7193 | base::RunLoop().RunUntilIdle(); |
| 7194 | |
| 7195 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7196 | |
| 7197 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 7198 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7199 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7200 | base::RunLoop().RunUntilIdle(); |
| 7201 | |
| 7202 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7203 | } |
| 7204 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7205 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 7206 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7207 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7208 | HttpRequestInfo request; |
| 7209 | request.method = "GET"; |
| 7210 | request.url = GURL("https://www.example.org/"); |
| 7211 | request.load_flags = 0; |
| 7212 | |
| 7213 | MockWrite data_writes[] = { |
| 7214 | MockWrite("GET / HTTP/1.1\r\n" |
| 7215 | "Host: www.example.org\r\n" |
| 7216 | "Connection: keep-alive\r\n\r\n"), |
| 7217 | }; |
| 7218 | |
| 7219 | MockRead data_reads[] = { |
| 7220 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7221 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 7222 | |
| 7223 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7224 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7225 | |
| 7226 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 7227 | arraysize(data_writes)); |
| 7228 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7229 | |
| 7230 | TestCompletionCallback callback; |
| 7231 | |
| 7232 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7233 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7234 | |
| 7235 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7236 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7237 | |
| 7238 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7240 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7241 | ASSERT_TRUE(response); |
| 7242 | ASSERT_TRUE(response->headers); |
| 7243 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7244 | |
| 7245 | // Make memory critical notification and ensure the transaction still has been |
| 7246 | // operating right. |
| 7247 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7248 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7249 | base::RunLoop().RunUntilIdle(); |
| 7250 | |
| 7251 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7252 | |
| 7253 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7254 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7255 | EXPECT_THAT(rv, IsOk()); |
| 7256 | EXPECT_EQ("hello world", response_data); |
| 7257 | |
| 7258 | // Empty the current queue. This is necessary because idle sockets are |
| 7259 | // added to the connection pool asynchronously with a PostTask. |
| 7260 | base::RunLoop().RunUntilIdle(); |
| 7261 | |
| 7262 | // We now check to make sure the socket was added back to the pool. |
| 7263 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7264 | |
| 7265 | // Make memory notification once again and ensure idle socket is closed. |
| 7266 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7267 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7268 | base::RunLoop().RunUntilIdle(); |
| 7269 | |
| 7270 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7271 | } |
| 7272 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7273 | // Make sure that we recycle a socket after a zero-length response. |
| 7274 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7275 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7276 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7277 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7278 | request.url = GURL( |
| 7279 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 7280 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 7281 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 7282 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7283 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7284 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7285 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7286 | MockRead data_reads[] = { |
| 7287 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 7288 | "Content-Length: 0\r\n" |
| 7289 | "Content-Type: text/html\r\n\r\n"), |
| 7290 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7291 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7292 | }; |
| 7293 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7294 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7295 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7296 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7297 | // Transaction must be created after the MockReads, so it's destroyed before |
| 7298 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7299 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7300 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7301 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7302 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7303 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7305 | |
| 7306 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7307 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7308 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7309 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7310 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7311 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7312 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7313 | std::string status_line = response->headers->GetStatusLine(); |
| 7314 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 7315 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7316 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7317 | |
| 7318 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7319 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7320 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7321 | EXPECT_EQ("", response_data); |
| 7322 | |
| 7323 | // Empty the current queue. This is necessary because idle sockets are |
| 7324 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7325 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7326 | |
| 7327 | // 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] | 7328 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7329 | } |
| 7330 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7331 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7332 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7333 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7334 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7335 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7336 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7337 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7338 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 7339 | // after use. |
| 7340 | request[0].method = "GET"; |
| 7341 | request[0].url = GURL("http://www.google.com/"); |
| 7342 | request[0].load_flags = 0; |
| 7343 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 7344 | // transaction 1. The first attempts fails when writing the POST data. |
| 7345 | // This causes the transaction to retry with a new socket. The second |
| 7346 | // attempt succeeds. |
| 7347 | request[1].method = "POST"; |
| 7348 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7349 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7350 | request[1].load_flags = 0; |
| 7351 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7353 | |
| 7354 | // The first socket is used for transaction 1 and the first attempt of |
| 7355 | // transaction 2. |
| 7356 | |
| 7357 | // The response of transaction 1. |
| 7358 | MockRead data_reads1[] = { |
| 7359 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 7360 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7361 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7362 | }; |
| 7363 | // The mock write results of transaction 1 and the first attempt of |
| 7364 | // transaction 2. |
| 7365 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7366 | MockWrite(SYNCHRONOUS, 64), // GET |
| 7367 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7368 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7369 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7370 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7371 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7372 | |
| 7373 | // The second socket is used for the second attempt of transaction 2. |
| 7374 | |
| 7375 | // The response of transaction 2. |
| 7376 | MockRead data_reads2[] = { |
| 7377 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 7378 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7379 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7380 | }; |
| 7381 | // The mock write results of the second attempt of transaction 2. |
| 7382 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7383 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7384 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7385 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7386 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7387 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7388 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7389 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7390 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7391 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7392 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7393 | "hello world", "welcome" |
| 7394 | }; |
| 7395 | |
| 7396 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7397 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7398 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7399 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7400 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7401 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7402 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7403 | |
| 7404 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7405 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7407 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7408 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7409 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7410 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7411 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7412 | |
| 7413 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7414 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7415 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7416 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7417 | } |
| 7418 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7419 | |
| 7420 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7421 | // 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] | 7422 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7423 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7424 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7425 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7426 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7427 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7428 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7430 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7431 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7432 | // The password contains an escaped character -- for this test to pass it |
| 7433 | // will need to be unescaped by HttpNetworkTransaction. |
| 7434 | EXPECT_EQ("b%40r", request.url.password()); |
| 7435 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7436 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7437 | MockWrite( |
| 7438 | "GET / HTTP/1.1\r\n" |
| 7439 | "Host: www.example.org\r\n" |
| 7440 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7441 | }; |
| 7442 | |
| 7443 | MockRead data_reads1[] = { |
| 7444 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7445 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7446 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7447 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7448 | }; |
| 7449 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7450 | // After the challenge above, the transaction will be restarted using the |
| 7451 | // identity from the url (foo, b@r) to answer the challenge. |
| 7452 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7453 | MockWrite( |
| 7454 | "GET / HTTP/1.1\r\n" |
| 7455 | "Host: www.example.org\r\n" |
| 7456 | "Connection: keep-alive\r\n" |
| 7457 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7458 | }; |
| 7459 | |
| 7460 | MockRead data_reads2[] = { |
| 7461 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7462 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7463 | MockRead(SYNCHRONOUS, OK), |
| 7464 | }; |
| 7465 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7466 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7467 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7468 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7469 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7470 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7471 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7473 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7474 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7476 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7477 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7478 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7479 | |
| 7480 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7481 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7482 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7483 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7484 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7485 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7487 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7488 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7489 | |
| 7490 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7491 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7492 | |
| 7493 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7494 | |
| 7495 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7496 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7497 | } |
| 7498 | |
| 7499 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7500 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7501 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7502 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7503 | HttpRequestInfo request; |
| 7504 | request.method = "GET"; |
| 7505 | // Note: the URL has a username:password in it. The password "baz" is |
| 7506 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7507 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7508 | |
| 7509 | request.load_flags = LOAD_NORMAL; |
| 7510 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7511 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7512 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7513 | |
| 7514 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7515 | MockWrite( |
| 7516 | "GET / HTTP/1.1\r\n" |
| 7517 | "Host: www.example.org\r\n" |
| 7518 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7519 | }; |
| 7520 | |
| 7521 | MockRead data_reads1[] = { |
| 7522 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7523 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7524 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7525 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7526 | }; |
| 7527 | |
| 7528 | // After the challenge above, the transaction will be restarted using the |
| 7529 | // identity from the url (foo, baz) to answer the challenge. |
| 7530 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7531 | MockWrite( |
| 7532 | "GET / HTTP/1.1\r\n" |
| 7533 | "Host: www.example.org\r\n" |
| 7534 | "Connection: keep-alive\r\n" |
| 7535 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7536 | }; |
| 7537 | |
| 7538 | MockRead data_reads2[] = { |
| 7539 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7540 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7541 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7542 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7543 | }; |
| 7544 | |
| 7545 | // After the challenge above, the transaction will be restarted using the |
| 7546 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7547 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7548 | MockWrite( |
| 7549 | "GET / HTTP/1.1\r\n" |
| 7550 | "Host: www.example.org\r\n" |
| 7551 | "Connection: keep-alive\r\n" |
| 7552 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7553 | }; |
| 7554 | |
| 7555 | MockRead data_reads3[] = { |
| 7556 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7557 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7558 | MockRead(SYNCHRONOUS, OK), |
| 7559 | }; |
| 7560 | |
| 7561 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7562 | data_writes1, arraysize(data_writes1)); |
| 7563 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7564 | data_writes2, arraysize(data_writes2)); |
| 7565 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7566 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7567 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7568 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7569 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7570 | |
| 7571 | TestCompletionCallback callback1; |
| 7572 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7573 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7574 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7575 | |
| 7576 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7577 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7578 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7579 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7580 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7581 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7582 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7583 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7584 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7585 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7587 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7588 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7589 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7590 | |
| 7591 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7592 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7593 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7594 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7595 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7596 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7597 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7598 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7599 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7600 | |
| 7601 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7602 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7603 | |
| 7604 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7605 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7606 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7607 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7608 | } |
| 7609 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7610 | |
| 7611 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7612 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7613 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7614 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7615 | HttpRequestInfo request; |
| 7616 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7617 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7618 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7619 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7620 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7621 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7622 | |
| 7623 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7624 | MockWrite( |
| 7625 | "GET / HTTP/1.1\r\n" |
| 7626 | "Host: www.example.org\r\n" |
| 7627 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7628 | }; |
| 7629 | |
| 7630 | MockRead data_reads1[] = { |
| 7631 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7632 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7633 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7634 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7635 | }; |
| 7636 | |
| 7637 | // After the challenge above, the transaction will be restarted using the |
| 7638 | // identity supplied by the user, not the one in the URL, to answer the |
| 7639 | // challenge. |
| 7640 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7641 | MockWrite( |
| 7642 | "GET / HTTP/1.1\r\n" |
| 7643 | "Host: www.example.org\r\n" |
| 7644 | "Connection: keep-alive\r\n" |
| 7645 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7646 | }; |
| 7647 | |
| 7648 | MockRead data_reads3[] = { |
| 7649 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7650 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7651 | MockRead(SYNCHRONOUS, OK), |
| 7652 | }; |
| 7653 | |
| 7654 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7655 | data_writes1, arraysize(data_writes1)); |
| 7656 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7657 | data_writes3, arraysize(data_writes3)); |
| 7658 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7659 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7660 | |
| 7661 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7662 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7663 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7664 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7665 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7666 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7667 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7668 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7669 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7670 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7671 | |
| 7672 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7673 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7674 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7675 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7676 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7677 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7678 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7679 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7680 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7681 | |
| 7682 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7683 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7684 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7685 | |
| 7686 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7687 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7688 | } |
| 7689 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7690 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7691 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7692 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7693 | |
| 7694 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7695 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7696 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7697 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7698 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7700 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7701 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7702 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7703 | MockWrite( |
| 7704 | "GET /x/y/z HTTP/1.1\r\n" |
| 7705 | "Host: www.example.org\r\n" |
| 7706 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7707 | }; |
| 7708 | |
| 7709 | MockRead data_reads1[] = { |
| 7710 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7711 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7712 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7713 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7714 | }; |
| 7715 | |
| 7716 | // Resend with authorization (username=foo, password=bar) |
| 7717 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7718 | MockWrite( |
| 7719 | "GET /x/y/z HTTP/1.1\r\n" |
| 7720 | "Host: www.example.org\r\n" |
| 7721 | "Connection: keep-alive\r\n" |
| 7722 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7723 | }; |
| 7724 | |
| 7725 | // Sever accepts the authorization. |
| 7726 | MockRead data_reads2[] = { |
| 7727 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7728 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7729 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7730 | }; |
| 7731 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7732 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7733 | data_writes1, arraysize(data_writes1)); |
| 7734 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7735 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7736 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7737 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7738 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7739 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7740 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7741 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7742 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7743 | |
| 7744 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7745 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7746 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7747 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7748 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7749 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7750 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7751 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7752 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7753 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7754 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7755 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7756 | |
| 7757 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7758 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7759 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7760 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7761 | ASSERT_TRUE(response); |
| 7762 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7763 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7764 | } |
| 7765 | |
| 7766 | // ------------------------------------------------------------------------ |
| 7767 | |
| 7768 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7769 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7770 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7771 | request.method = "GET"; |
| 7772 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7773 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7774 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7776 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7777 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7778 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7779 | MockWrite( |
| 7780 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7781 | "Host: www.example.org\r\n" |
| 7782 | "Connection: keep-alive\r\n" |
| 7783 | // Send preemptive authorization for MyRealm1 |
| 7784 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7785 | }; |
| 7786 | |
| 7787 | // The server didn't like the preemptive authorization, and |
| 7788 | // challenges us for a different realm (MyRealm2). |
| 7789 | MockRead data_reads1[] = { |
| 7790 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7791 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7792 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7793 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7794 | }; |
| 7795 | |
| 7796 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7797 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7798 | MockWrite( |
| 7799 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7800 | "Host: www.example.org\r\n" |
| 7801 | "Connection: keep-alive\r\n" |
| 7802 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7803 | }; |
| 7804 | |
| 7805 | // Sever accepts the authorization. |
| 7806 | MockRead data_reads2[] = { |
| 7807 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7808 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7809 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7810 | }; |
| 7811 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7812 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7813 | data_writes1, arraysize(data_writes1)); |
| 7814 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7815 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7816 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7817 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7818 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7819 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7820 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7821 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7823 | |
| 7824 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7825 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7827 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7828 | ASSERT_TRUE(response); |
| 7829 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7830 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7831 | EXPECT_EQ("http://www.example.org", |
| 7832 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7833 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7834 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7836 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7837 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7838 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7839 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7841 | |
| 7842 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7843 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7845 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7846 | ASSERT_TRUE(response); |
| 7847 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7848 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7849 | } |
| 7850 | |
| 7851 | // ------------------------------------------------------------------------ |
| 7852 | |
| 7853 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7854 | // succeed with preemptive authorization. |
| 7855 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7856 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7857 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7858 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7859 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7860 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7861 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7862 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7863 | MockWrite( |
| 7864 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7865 | "Host: www.example.org\r\n" |
| 7866 | "Connection: keep-alive\r\n" |
| 7867 | // The authorization for MyRealm1 gets sent preemptively |
| 7868 | // (since the url is in the same protection space) |
| 7869 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7870 | }; |
| 7871 | |
| 7872 | // Sever accepts the preemptive authorization |
| 7873 | MockRead data_reads1[] = { |
| 7874 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7875 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7876 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7877 | }; |
| 7878 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7879 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7880 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7881 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7882 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7883 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7884 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7885 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7886 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7887 | |
| 7888 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7889 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7890 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7891 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7892 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7893 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7894 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7895 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7896 | } |
| 7897 | |
| 7898 | // ------------------------------------------------------------------------ |
| 7899 | |
| 7900 | // Transaction 4: request another URL in MyRealm (however the |
| 7901 | // url is not known to belong to the protection space, so no pre-auth). |
| 7902 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7903 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7904 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7905 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7906 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7907 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7908 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7909 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7910 | MockWrite( |
| 7911 | "GET /x/1 HTTP/1.1\r\n" |
| 7912 | "Host: www.example.org\r\n" |
| 7913 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7914 | }; |
| 7915 | |
| 7916 | MockRead data_reads1[] = { |
| 7917 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7918 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7919 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7920 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7921 | }; |
| 7922 | |
| 7923 | // Resend with authorization from MyRealm's cache. |
| 7924 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7925 | MockWrite( |
| 7926 | "GET /x/1 HTTP/1.1\r\n" |
| 7927 | "Host: www.example.org\r\n" |
| 7928 | "Connection: keep-alive\r\n" |
| 7929 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7930 | }; |
| 7931 | |
| 7932 | // Sever accepts the authorization. |
| 7933 | MockRead data_reads2[] = { |
| 7934 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7935 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7936 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7937 | }; |
| 7938 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7939 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7940 | data_writes1, arraysize(data_writes1)); |
| 7941 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7942 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7943 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7944 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7945 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7946 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7947 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7948 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7949 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7950 | |
| 7951 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7952 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7953 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7954 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7955 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7956 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7957 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7958 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7959 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7960 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7962 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7963 | ASSERT_TRUE(response); |
| 7964 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7965 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7966 | } |
| 7967 | |
| 7968 | // ------------------------------------------------------------------------ |
| 7969 | |
| 7970 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7971 | // cached identity. Should invalidate and re-prompt. |
| 7972 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7973 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7974 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7975 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7976 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7977 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7978 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7979 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7980 | MockWrite( |
| 7981 | "GET /p/q/t HTTP/1.1\r\n" |
| 7982 | "Host: www.example.org\r\n" |
| 7983 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7984 | }; |
| 7985 | |
| 7986 | MockRead data_reads1[] = { |
| 7987 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7988 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7989 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7990 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7991 | }; |
| 7992 | |
| 7993 | // Resend with authorization from cache for MyRealm. |
| 7994 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7995 | MockWrite( |
| 7996 | "GET /p/q/t HTTP/1.1\r\n" |
| 7997 | "Host: www.example.org\r\n" |
| 7998 | "Connection: keep-alive\r\n" |
| 7999 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8000 | }; |
| 8001 | |
| 8002 | // Sever rejects the authorization. |
| 8003 | MockRead data_reads2[] = { |
| 8004 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8005 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8006 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8007 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8008 | }; |
| 8009 | |
| 8010 | // At this point we should prompt for new credentials for MyRealm. |
| 8011 | // Restart with username=foo3, password=foo4. |
| 8012 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8013 | MockWrite( |
| 8014 | "GET /p/q/t HTTP/1.1\r\n" |
| 8015 | "Host: www.example.org\r\n" |
| 8016 | "Connection: keep-alive\r\n" |
| 8017 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8018 | }; |
| 8019 | |
| 8020 | // Sever accepts the authorization. |
| 8021 | MockRead data_reads3[] = { |
| 8022 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8023 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8024 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8025 | }; |
| 8026 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8027 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8028 | data_writes1, arraysize(data_writes1)); |
| 8029 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8030 | data_writes2, arraysize(data_writes2)); |
| 8031 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8032 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8033 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8034 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8035 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8036 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8037 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8038 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8039 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8040 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8041 | |
| 8042 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8043 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8044 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8045 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8046 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8047 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8048 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8049 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8050 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8051 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8052 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8053 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8054 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8055 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8057 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8058 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8059 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 8060 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8061 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8062 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8063 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8064 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8065 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8066 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8067 | ASSERT_TRUE(response); |
| 8068 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8069 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8070 | } |
| 8071 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8072 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8073 | // Tests that nonce count increments when multiple auth attempts |
| 8074 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8075 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 8076 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 8077 | new HttpAuthHandlerDigest::Factory(); |
| 8078 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 8079 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 8080 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8081 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8082 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8083 | |
| 8084 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8085 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8086 | HttpRequestInfo request; |
| 8087 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8088 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8089 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8090 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8091 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8092 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8093 | MockWrite( |
| 8094 | "GET /x/y/z HTTP/1.1\r\n" |
| 8095 | "Host: www.example.org\r\n" |
| 8096 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8097 | }; |
| 8098 | |
| 8099 | MockRead data_reads1[] = { |
| 8100 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8101 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 8102 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8103 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8104 | }; |
| 8105 | |
| 8106 | // Resend with authorization (username=foo, password=bar) |
| 8107 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8108 | MockWrite( |
| 8109 | "GET /x/y/z HTTP/1.1\r\n" |
| 8110 | "Host: www.example.org\r\n" |
| 8111 | "Connection: keep-alive\r\n" |
| 8112 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8113 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 8114 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 8115 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8116 | }; |
| 8117 | |
| 8118 | // Sever accepts the authorization. |
| 8119 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8120 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8121 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8122 | }; |
| 8123 | |
| 8124 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8125 | data_writes1, arraysize(data_writes1)); |
| 8126 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8127 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8128 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8129 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8130 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8131 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8132 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8133 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8134 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8135 | |
| 8136 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8137 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8139 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8140 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8141 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8142 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8143 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8144 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8145 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8146 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8147 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8148 | |
| 8149 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8150 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8151 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8152 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8153 | ASSERT_TRUE(response); |
| 8154 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8155 | } |
| 8156 | |
| 8157 | // ------------------------------------------------------------------------ |
| 8158 | |
| 8159 | // Transaction 2: Request another resource in digestive's protection space. |
| 8160 | // This will preemptively add an Authorization header which should have an |
| 8161 | // "nc" value of 2 (as compared to 1 in the first use. |
| 8162 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8163 | HttpRequestInfo request; |
| 8164 | request.method = "GET"; |
| 8165 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8166 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8167 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8168 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8169 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8170 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8171 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8172 | MockWrite( |
| 8173 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8174 | "Host: www.example.org\r\n" |
| 8175 | "Connection: keep-alive\r\n" |
| 8176 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8177 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 8178 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 8179 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8180 | }; |
| 8181 | |
| 8182 | // Sever accepts the authorization. |
| 8183 | MockRead data_reads1[] = { |
| 8184 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8185 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8186 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8187 | }; |
| 8188 | |
| 8189 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8190 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8191 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8192 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8193 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8194 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8195 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8196 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8197 | |
| 8198 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8199 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8200 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8201 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8202 | ASSERT_TRUE(response); |
| 8203 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8204 | } |
| 8205 | } |
| 8206 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8207 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8208 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8209 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8210 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8211 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8212 | |
| 8213 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8214 | trans.read_buf_ = new IOBuffer(15); |
| 8215 | trans.read_buf_len_ = 15; |
| 8216 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8217 | |
| 8218 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8219 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8220 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8221 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8222 | response->response_time = base::Time::Now(); |
| 8223 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8224 | |
| 8225 | { // Setup state for response_.vary_data |
| 8226 | HttpRequestInfo request; |
| 8227 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 8228 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 8229 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8230 | request.extra_headers.SetHeader("Foo", "1"); |
| 8231 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8232 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8233 | } |
| 8234 | |
| 8235 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8236 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8237 | |
| 8238 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8239 | EXPECT_FALSE(trans.read_buf_); |
| 8240 | EXPECT_EQ(0, trans.read_buf_len_); |
| 8241 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8242 | EXPECT_FALSE(response->auth_challenge); |
| 8243 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 8244 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8245 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8246 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8247 | } |
| 8248 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8249 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8250 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8251 | HttpRequestInfo request; |
| 8252 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8253 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8254 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8255 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8256 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8257 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8258 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8259 | MockWrite( |
| 8260 | "GET / HTTP/1.1\r\n" |
| 8261 | "Host: www.example.org\r\n" |
| 8262 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8263 | }; |
| 8264 | |
| 8265 | MockRead data_reads[] = { |
| 8266 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8267 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8268 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8269 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8270 | }; |
| 8271 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 8272 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8273 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8274 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8275 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8276 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8277 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8278 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8279 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8280 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8282 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8283 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8284 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8285 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8286 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8287 | |
| 8288 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8289 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8290 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8291 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8292 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8293 | |
| 8294 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8295 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8296 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8297 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8298 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8299 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8300 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8301 | } |
| 8302 | |
| 8303 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 8304 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8305 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 8306 | session_deps_.proxy_resolution_service = |
| 8307 | ProxyResolutionService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8308 | |
| 8309 | HttpRequestInfo request; |
| 8310 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8311 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8312 | |
| 8313 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8314 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8315 | "Host: www.example.org:443\r\n" |
| 8316 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8317 | }; |
| 8318 | |
| 8319 | MockRead proxy_reads[] = { |
| 8320 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8321 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8322 | }; |
| 8323 | |
| 8324 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8325 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8326 | "Host: www.example.org:443\r\n" |
| 8327 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8328 | MockWrite("GET / HTTP/1.1\r\n" |
| 8329 | "Host: www.example.org\r\n" |
| 8330 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8331 | }; |
| 8332 | |
| 8333 | MockRead data_reads[] = { |
| 8334 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8335 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8336 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8337 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8338 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8339 | }; |
| 8340 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8341 | StaticSocketDataProvider ssl_bad_certificate( |
| 8342 | proxy_reads, arraysize(proxy_reads), |
| 8343 | proxy_writes, arraysize(proxy_writes)); |
| 8344 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8345 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8346 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8347 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8348 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8349 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8350 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8351 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8352 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8353 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8354 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8355 | |
| 8356 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8357 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8358 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8359 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8360 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8361 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8362 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8363 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8364 | |
| 8365 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8366 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8367 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8368 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8369 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8370 | |
| 8371 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8372 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8373 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8374 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8375 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8376 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8377 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8378 | } |
| 8379 | } |
| 8380 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8381 | |
| 8382 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8383 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 8384 | session_deps_.proxy_resolution_service = |
| 8385 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8386 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8387 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8388 | |
| 8389 | HttpRequestInfo request; |
| 8390 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8391 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8392 | |
| 8393 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8394 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8395 | "Host: www.example.org:443\r\n" |
| 8396 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8397 | MockWrite("GET / HTTP/1.1\r\n" |
| 8398 | "Host: www.example.org\r\n" |
| 8399 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8400 | }; |
| 8401 | |
| 8402 | MockRead data_reads[] = { |
| 8403 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8404 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8405 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8406 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8407 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8408 | }; |
| 8409 | |
| 8410 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8411 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8412 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8413 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8414 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8415 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8417 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8418 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8419 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8420 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8422 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8423 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8424 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8425 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8426 | |
| 8427 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8428 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8429 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8430 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8431 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8432 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8433 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8434 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8435 | EXPECT_EQ(200, response->headers->response_code()); |
| 8436 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8437 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8438 | |
| 8439 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8440 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8441 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8442 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8443 | } |
| 8444 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8445 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8446 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 8447 | session_deps_.proxy_resolution_service = |
| 8448 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8449 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8450 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8451 | |
| 8452 | HttpRequestInfo request; |
| 8453 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8454 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8455 | |
| 8456 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8457 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8458 | "Host: www.example.org:443\r\n" |
| 8459 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8460 | }; |
| 8461 | |
| 8462 | MockRead data_reads[] = { |
| 8463 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8464 | MockRead("Location: http://login.example.com/\r\n"), |
| 8465 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8466 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8467 | }; |
| 8468 | |
| 8469 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8470 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8471 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8472 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8473 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8474 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8476 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8477 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8478 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8479 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8480 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8481 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8482 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8483 | |
| 8484 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8485 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8486 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8487 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8488 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8489 | |
| 8490 | EXPECT_EQ(302, response->headers->response_code()); |
| 8491 | std::string url; |
| 8492 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8493 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8494 | |
| 8495 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8496 | // timing for the proxy connection instead of the connection to the host, |
| 8497 | // and no send / receive times. |
| 8498 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8499 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8500 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8501 | |
| 8502 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8503 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8504 | |
| 8505 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8506 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8507 | load_timing_info.proxy_resolve_end); |
| 8508 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8509 | load_timing_info.connect_timing.connect_start); |
| 8510 | ExpectConnectTimingHasTimes( |
| 8511 | load_timing_info.connect_timing, |
| 8512 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8513 | |
| 8514 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8515 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8516 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8517 | } |
| 8518 | |
| 8519 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8520 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 8521 | session_deps_.proxy_resolution_service = |
| 8522 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8523 | |
| 8524 | HttpRequestInfo request; |
| 8525 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8526 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8527 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8528 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8529 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8530 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8531 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8532 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8533 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8534 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8535 | }; |
| 8536 | |
| 8537 | static const char* const kExtraHeaders[] = { |
| 8538 | "location", |
| 8539 | "http://login.example.com/", |
| 8540 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8541 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8542 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8543 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8544 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8545 | }; |
| 8546 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8547 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8548 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8549 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8550 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8551 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8552 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8553 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8554 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8555 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8556 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8557 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8558 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8559 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8560 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8561 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8562 | |
| 8563 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8564 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8565 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8566 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8567 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8568 | |
| 8569 | EXPECT_EQ(302, response->headers->response_code()); |
| 8570 | std::string url; |
| 8571 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8572 | EXPECT_EQ("http://login.example.com/", url); |
| 8573 | } |
| 8574 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8575 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8576 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 8577 | session_deps_.proxy_resolution_service = |
| 8578 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8579 | |
| 8580 | HttpRequestInfo request; |
| 8581 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8582 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8583 | |
| 8584 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8585 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8586 | "Host: www.example.org:443\r\n" |
| 8587 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8588 | }; |
| 8589 | |
| 8590 | MockRead data_reads[] = { |
| 8591 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8592 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8593 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8594 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8595 | }; |
| 8596 | |
| 8597 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8598 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8599 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8600 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8601 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8602 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8603 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8604 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8605 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8606 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8607 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [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] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8611 | |
| 8612 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8613 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8614 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8615 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8616 | } |
| 8617 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8618 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8619 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 8620 | session_deps_.proxy_resolution_service = |
| 8621 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8622 | |
| 8623 | HttpRequestInfo request; |
| 8624 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8625 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8626 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8627 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8628 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8629 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8630 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8631 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8632 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8633 | }; |
| 8634 | |
| 8635 | static const char* const kExtraHeaders[] = { |
| 8636 | "location", |
| 8637 | "http://login.example.com/", |
| 8638 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8639 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8640 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8641 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8642 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8643 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8644 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8645 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8646 | }; |
| 8647 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8648 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8649 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8650 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8651 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8652 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8653 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8654 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8655 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8656 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [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] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8660 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8661 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8662 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8663 | |
| 8664 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8665 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8666 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8667 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8668 | } |
| 8669 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8670 | // Test the request-challenge-retry sequence for basic auth, through |
| 8671 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8672 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8673 | HttpRequestInfo request; |
| 8674 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8675 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8676 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8677 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8678 | |
| 8679 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 8680 | session_deps_.proxy_resolution_service = |
| 8681 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8682 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8683 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8684 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8685 | |
| 8686 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8687 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8688 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8689 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8690 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8691 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8692 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8693 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8694 | // be issuing -- the final header line contains the credentials. |
| 8695 | const char* const kAuthCredentials[] = { |
| 8696 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8697 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8698 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8699 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8700 | HostPortPair("www.example.org", 443))); |
| 8701 | // fetch https://www.example.org/ via HTTP |
| 8702 | const char get[] = |
| 8703 | "GET / HTTP/1.1\r\n" |
| 8704 | "Host: www.example.org\r\n" |
| 8705 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8706 | SpdySerializedFrame wrapped_get( |
| 8707 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8708 | |
| 8709 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8710 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8711 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8712 | }; |
| 8713 | |
| 8714 | // The proxy responds to the connect with a 407, using a persistent |
| 8715 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8716 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8717 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8718 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8719 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8720 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8721 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8722 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8723 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8724 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8725 | "Content-Length: 5\r\n\r\n"; |
| 8726 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8727 | SpdySerializedFrame wrapped_get_resp( |
| 8728 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8729 | SpdySerializedFrame wrapped_body( |
| 8730 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8731 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8732 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8733 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8734 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8735 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8736 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8737 | }; |
| 8738 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8739 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8740 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8741 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8742 | // Negotiate SPDY to the proxy |
| 8743 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8744 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8745 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8746 | // Vanilla SSL to the server |
| 8747 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8748 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8749 | |
| 8750 | TestCompletionCallback callback1; |
| 8751 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8752 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8753 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8754 | |
| 8755 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8757 | |
| 8758 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8759 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8760 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8761 | log.GetEntries(&entries); |
| 8762 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8763 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8764 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8765 | ExpectLogContainsSomewhere( |
| 8766 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8767 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8768 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8769 | |
| 8770 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8771 | ASSERT_TRUE(response); |
| 8772 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8773 | EXPECT_EQ(407, response->headers->response_code()); |
| 8774 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8775 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8776 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8777 | |
| 8778 | TestCompletionCallback callback2; |
| 8779 | |
| 8780 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8781 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8782 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8783 | |
| 8784 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8785 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8786 | |
| 8787 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8788 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8789 | |
| 8790 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8791 | EXPECT_EQ(200, response->headers->response_code()); |
| 8792 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8793 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8794 | |
| 8795 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8796 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8797 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8798 | LoadTimingInfo load_timing_info; |
| 8799 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8800 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8801 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8802 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8803 | trans.reset(); |
| 8804 | session->CloseAllConnections(); |
| 8805 | } |
| 8806 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8807 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8808 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8809 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8810 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8811 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8812 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8813 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8814 | HttpRequestInfo request; |
| 8815 | HttpRequestInfo push_request; |
| 8816 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8817 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8818 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8819 | push_request.method = "GET"; |
| 8820 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8821 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8822 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 8823 | session_deps_.proxy_resolution_service = |
| 8824 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8825 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8826 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8827 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8828 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8829 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8830 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8831 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8832 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8833 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8834 | SpdySerializedFrame stream2_priority( |
| 8835 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8836 | |
| 8837 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8838 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8839 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8840 | }; |
| 8841 | |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 8842 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
| 8843 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 8844 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8845 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8846 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8847 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8848 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8849 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8850 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8851 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8852 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8853 | |
| 8854 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 8855 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 8856 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8857 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8858 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8859 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8860 | }; |
| 8861 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8862 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8863 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8864 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8865 | // Negotiate SPDY to the proxy |
| 8866 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8867 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8868 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8869 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8870 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8871 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8872 | TestCompletionCallback callback; |
| 8873 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8874 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8875 | |
| 8876 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8877 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8878 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8879 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8880 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8881 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8882 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8883 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8884 | |
| 8885 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8886 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8887 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8888 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8889 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8890 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8891 | |
| 8892 | EXPECT_EQ(200, response->headers->response_code()); |
| 8893 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8894 | |
| 8895 | std::string response_data; |
| 8896 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8897 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8898 | EXPECT_EQ("hello!", response_data); |
| 8899 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8900 | LoadTimingInfo load_timing_info; |
| 8901 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8902 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8903 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8904 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8905 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8906 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8907 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8908 | |
| 8909 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8910 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8911 | EXPECT_EQ("pushed", response_data); |
| 8912 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8913 | LoadTimingInfo push_load_timing_info; |
| 8914 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8915 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8916 | // The transactions should share a socket ID, despite being for different |
| 8917 | // origins. |
| 8918 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8919 | push_load_timing_info.socket_log_id); |
| 8920 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8921 | trans.reset(); |
| 8922 | push_trans.reset(); |
| 8923 | session->CloseAllConnections(); |
| 8924 | } |
| 8925 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8926 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8927 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8928 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8929 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8930 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8931 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8932 | HttpRequestInfo request; |
| 8933 | |
| 8934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8935 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8936 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 8937 | session_deps_.proxy_resolution_service = |
| 8938 | ProxyResolutionService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8939 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8940 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8941 | |
| 8942 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8943 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8944 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8945 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8946 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8947 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8948 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8949 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8950 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8951 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8952 | |
| 8953 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8954 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8955 | }; |
| 8956 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8957 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8958 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8959 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8960 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8961 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8962 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8963 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8964 | |
| 8965 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8966 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8967 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8968 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8969 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8970 | }; |
| 8971 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8972 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8973 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8974 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8975 | // Negotiate SPDY to the proxy |
| 8976 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8977 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8978 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8979 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8980 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8981 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8982 | TestCompletionCallback callback; |
| 8983 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8984 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8985 | |
| 8986 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8987 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8988 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8989 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8990 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8991 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8992 | |
| 8993 | EXPECT_EQ(200, response->headers->response_code()); |
| 8994 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8995 | |
| 8996 | std::string response_data; |
| 8997 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8998 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8999 | EXPECT_EQ("hello!", response_data); |
| 9000 | |
| 9001 | trans.reset(); |
| 9002 | session->CloseAllConnections(); |
| 9003 | } |
| 9004 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9005 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 9006 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9007 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9008 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9009 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9010 | proxy_delegate->set_trusted_spdy_proxy( |
| 9011 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 9012 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9013 | HttpRequestInfo request; |
| 9014 | |
| 9015 | request.method = "GET"; |
| 9016 | request.url = GURL("http://www.example.org/"); |
| 9017 | |
| 9018 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 9019 | session_deps_.proxy_resolution_service = |
| 9020 | ProxyResolutionService::CreateFixed("https://myproxy:70"); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9021 | BoundTestNetLog log; |
| 9022 | session_deps_.net_log = log.bound().net_log(); |
| 9023 | |
| 9024 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9025 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9026 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9027 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9028 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9029 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9030 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9031 | SpdySerializedFrame stream2_priority( |
| 9032 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9033 | |
| 9034 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9035 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9036 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9037 | }; |
| 9038 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9039 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9040 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9041 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9042 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 9043 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 9044 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9045 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9046 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9047 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9048 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9049 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9050 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9051 | |
| 9052 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9053 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9054 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9055 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9056 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9057 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9058 | }; |
| 9059 | |
| 9060 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9061 | arraysize(spdy_writes)); |
| 9062 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 9063 | // Negotiate SPDY to the proxy |
| 9064 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9065 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9066 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 9067 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9068 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9069 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9070 | TestCompletionCallback callback; |
| 9071 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9072 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9073 | |
| 9074 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9075 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9076 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9077 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9078 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9079 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9080 | |
| 9081 | EXPECT_EQ(200, response->headers->response_code()); |
| 9082 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9083 | |
| 9084 | std::string response_data; |
| 9085 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9086 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9087 | EXPECT_EQ("hello!", response_data); |
| 9088 | |
| 9089 | trans.reset(); |
| 9090 | session->CloseAllConnections(); |
| 9091 | } |
| 9092 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9093 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 9094 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9095 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 9096 | session_deps_.proxy_resolution_service = |
| 9097 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9098 | |
| 9099 | HttpRequestInfo request; |
| 9100 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9101 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9102 | |
| 9103 | // Attempt to fetch the URL from a server with a bad cert |
| 9104 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9105 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9106 | "Host: www.example.org:443\r\n" |
| 9107 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9108 | }; |
| 9109 | |
| 9110 | MockRead bad_cert_reads[] = { |
| 9111 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9112 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9113 | }; |
| 9114 | |
| 9115 | // Attempt to fetch the URL with a good cert |
| 9116 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9117 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9118 | "Host: www.example.org:443\r\n" |
| 9119 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9120 | MockWrite("GET / HTTP/1.1\r\n" |
| 9121 | "Host: www.example.org\r\n" |
| 9122 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9123 | }; |
| 9124 | |
| 9125 | MockRead good_cert_reads[] = { |
| 9126 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9127 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9128 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9129 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9130 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9131 | }; |
| 9132 | |
| 9133 | StaticSocketDataProvider ssl_bad_certificate( |
| 9134 | bad_cert_reads, arraysize(bad_cert_reads), |
| 9135 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 9136 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 9137 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9138 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9139 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9140 | |
| 9141 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9142 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9143 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9144 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9145 | |
| 9146 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9148 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9149 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9150 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9151 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9152 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9153 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9154 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9155 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9156 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9157 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9158 | |
| 9159 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9160 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9161 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9162 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9164 | |
| 9165 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9166 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9167 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9168 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9169 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9170 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9171 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9172 | } |
| 9173 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9174 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9175 | HttpRequestInfo request; |
| 9176 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9177 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9178 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9179 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9180 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9181 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9182 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9183 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9184 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9185 | MockWrite( |
| 9186 | "GET / HTTP/1.1\r\n" |
| 9187 | "Host: www.example.org\r\n" |
| 9188 | "Connection: keep-alive\r\n" |
| 9189 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9190 | }; |
| 9191 | |
| 9192 | // Lastly, the server responds with the actual content. |
| 9193 | MockRead data_reads[] = { |
| 9194 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9195 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9196 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9197 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9198 | }; |
| 9199 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9200 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9201 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9202 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9203 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9204 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9205 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9206 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9207 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9208 | |
| 9209 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9210 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9211 | } |
| 9212 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9213 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9214 | HttpRequestInfo request; |
| 9215 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9216 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9217 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9218 | "Chromium Ultra Awesome X Edition"); |
| 9219 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 9220 | session_deps_.proxy_resolution_service = |
| 9221 | ProxyResolutionService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9223 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9224 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9225 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9226 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9227 | "Host: www.example.org:443\r\n" |
| 9228 | "Proxy-Connection: keep-alive\r\n" |
| 9229 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9230 | }; |
| 9231 | MockRead data_reads[] = { |
| 9232 | // Return an error, so the transaction stops here (this test isn't |
| 9233 | // interested in the rest). |
| 9234 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 9235 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9236 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 9237 | }; |
| 9238 | |
| 9239 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9240 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9241 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9243 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9244 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9245 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9246 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9247 | |
| 9248 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9249 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9250 | } |
| 9251 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9252 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9253 | HttpRequestInfo request; |
| 9254 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9255 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 9256 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 9257 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9258 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9259 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9260 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9261 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9262 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9263 | MockWrite( |
| 9264 | "GET / HTTP/1.1\r\n" |
| 9265 | "Host: www.example.org\r\n" |
| 9266 | "Connection: keep-alive\r\n" |
| 9267 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9268 | }; |
| 9269 | |
| 9270 | // Lastly, the server responds with the actual content. |
| 9271 | MockRead data_reads[] = { |
| 9272 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9273 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9274 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9275 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9276 | }; |
| 9277 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9278 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9279 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9280 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9281 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9282 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9283 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9284 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9285 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9286 | |
| 9287 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9288 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9289 | } |
| 9290 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9291 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9292 | HttpRequestInfo request; |
| 9293 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9294 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9295 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9296 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9297 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9298 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9299 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9300 | MockWrite( |
| 9301 | "POST / HTTP/1.1\r\n" |
| 9302 | "Host: www.example.org\r\n" |
| 9303 | "Connection: keep-alive\r\n" |
| 9304 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9305 | }; |
| 9306 | |
| 9307 | // Lastly, the server responds with the actual content. |
| 9308 | MockRead data_reads[] = { |
| 9309 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9310 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9311 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9312 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9313 | }; |
| 9314 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9315 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9316 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9317 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9319 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9320 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9321 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9322 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9323 | |
| 9324 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9325 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9326 | } |
| 9327 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9328 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9329 | HttpRequestInfo request; |
| 9330 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9331 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9332 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9333 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9334 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9335 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9336 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9337 | MockWrite( |
| 9338 | "PUT / HTTP/1.1\r\n" |
| 9339 | "Host: www.example.org\r\n" |
| 9340 | "Connection: keep-alive\r\n" |
| 9341 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9342 | }; |
| 9343 | |
| 9344 | // Lastly, the server responds with the actual content. |
| 9345 | MockRead data_reads[] = { |
| 9346 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9347 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9348 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9349 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9350 | }; |
| 9351 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9352 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9353 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9354 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9355 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9356 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9357 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9358 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9359 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9360 | |
| 9361 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9362 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9363 | } |
| 9364 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9365 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9366 | HttpRequestInfo request; |
| 9367 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9368 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9369 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9370 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9371 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9372 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9373 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 9374 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 9375 | "Host: www.example.org\r\n" |
| 9376 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9377 | }; |
| 9378 | |
| 9379 | // Lastly, the server responds with the actual content. |
| 9380 | MockRead data_reads[] = { |
| 9381 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9382 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9383 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9384 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9385 | }; |
| 9386 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9387 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9388 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9389 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9390 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9391 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9392 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9393 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9394 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9395 | |
| 9396 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9397 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9398 | } |
| 9399 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9400 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9401 | HttpRequestInfo request; |
| 9402 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9403 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9404 | request.load_flags = LOAD_BYPASS_CACHE; |
| 9405 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9406 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9407 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9408 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9409 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9410 | MockWrite( |
| 9411 | "GET / HTTP/1.1\r\n" |
| 9412 | "Host: www.example.org\r\n" |
| 9413 | "Connection: keep-alive\r\n" |
| 9414 | "Pragma: no-cache\r\n" |
| 9415 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9416 | }; |
| 9417 | |
| 9418 | // Lastly, the server responds with the actual content. |
| 9419 | MockRead data_reads[] = { |
| 9420 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9421 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9422 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9423 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9424 | }; |
| 9425 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9426 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9427 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9428 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9429 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9430 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9431 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9432 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9433 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9434 | |
| 9435 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9436 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9437 | } |
| 9438 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9439 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9440 | HttpRequestInfo request; |
| 9441 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9442 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9443 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 9444 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9445 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9446 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9447 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9448 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9449 | MockWrite( |
| 9450 | "GET / HTTP/1.1\r\n" |
| 9451 | "Host: www.example.org\r\n" |
| 9452 | "Connection: keep-alive\r\n" |
| 9453 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9454 | }; |
| 9455 | |
| 9456 | // Lastly, the server responds with the actual content. |
| 9457 | MockRead data_reads[] = { |
| 9458 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9459 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9460 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9461 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9462 | }; |
| 9463 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9464 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9465 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9466 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9467 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9468 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9469 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9470 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9471 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9472 | |
| 9473 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9474 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9475 | } |
| 9476 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9477 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9478 | HttpRequestInfo request; |
| 9479 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9480 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9481 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9482 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9483 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9484 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9485 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9486 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9487 | MockWrite( |
| 9488 | "GET / HTTP/1.1\r\n" |
| 9489 | "Host: www.example.org\r\n" |
| 9490 | "Connection: keep-alive\r\n" |
| 9491 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9492 | }; |
| 9493 | |
| 9494 | // Lastly, the server responds with the actual content. |
| 9495 | MockRead data_reads[] = { |
| 9496 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9497 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9498 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9499 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9500 | }; |
| 9501 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9502 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9503 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9504 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9505 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9506 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9507 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9508 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9509 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9510 | |
| 9511 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9512 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9513 | } |
| 9514 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9515 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9516 | HttpRequestInfo request; |
| 9517 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9518 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9519 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9520 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9521 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9522 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9523 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9524 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9525 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9526 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9527 | MockWrite( |
| 9528 | "GET / HTTP/1.1\r\n" |
| 9529 | "Host: www.example.org\r\n" |
| 9530 | "Connection: keep-alive\r\n" |
| 9531 | "referer: www.foo.com\r\n" |
| 9532 | "hEllo: Kitty\r\n" |
| 9533 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9534 | }; |
| 9535 | |
| 9536 | // Lastly, the server responds with the actual content. |
| 9537 | MockRead data_reads[] = { |
| 9538 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9539 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9540 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9541 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9542 | }; |
| 9543 | |
| 9544 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9545 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9546 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9547 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9548 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9549 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9550 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9551 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9552 | |
| 9553 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9554 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9555 | } |
| 9556 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9557 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9558 | HttpRequestInfo request; |
| 9559 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9560 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9561 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 9562 | session_deps_.proxy_resolution_service = |
| 9563 | ProxyResolutionService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9564 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9565 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9566 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9567 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9568 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9569 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9570 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9571 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9572 | |
| 9573 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9574 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9575 | MockWrite( |
| 9576 | "GET / HTTP/1.1\r\n" |
| 9577 | "Host: www.example.org\r\n" |
| 9578 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9579 | |
| 9580 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9581 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9582 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9583 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9584 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9585 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9586 | }; |
| 9587 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9588 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9589 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9590 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9591 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9592 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9593 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9594 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9595 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9596 | |
| 9597 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9598 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9599 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9600 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9601 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9602 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9603 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9604 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9605 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9606 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9607 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9608 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9609 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9610 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9611 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9612 | EXPECT_EQ("Payload", response_text); |
| 9613 | } |
| 9614 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9615 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9616 | HttpRequestInfo request; |
| 9617 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9618 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9619 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 9620 | session_deps_.proxy_resolution_service = |
| 9621 | ProxyResolutionService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9622 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9623 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9624 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9625 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9627 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9628 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9629 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9630 | |
| 9631 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9632 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9633 | arraysize(write_buffer)), |
| 9634 | MockWrite( |
| 9635 | "GET / HTTP/1.1\r\n" |
| 9636 | "Host: www.example.org\r\n" |
| 9637 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9638 | |
| 9639 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9640 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9641 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9642 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9643 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9644 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9645 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9646 | }; |
| 9647 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9648 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9649 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9650 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9651 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9652 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9653 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9654 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9655 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9656 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9657 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9658 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9659 | |
| 9660 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9661 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9662 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9663 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9664 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9665 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9666 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9667 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9668 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9669 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9670 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9671 | |
| 9672 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9673 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9674 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9675 | EXPECT_EQ("Payload", response_text); |
| 9676 | } |
| 9677 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9678 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9679 | HttpRequestInfo request; |
| 9680 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9681 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9682 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 9683 | session_deps_.proxy_resolution_service = |
| 9684 | ProxyResolutionService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9685 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9686 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9687 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9689 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9690 | |
| 9691 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9692 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9693 | |
| 9694 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9695 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9696 | MockWrite( |
| 9697 | "GET / HTTP/1.1\r\n" |
| 9698 | "Host: www.example.org\r\n" |
| 9699 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9700 | |
| 9701 | MockRead data_reads[] = { |
| 9702 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9703 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9704 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9705 | MockRead("Payload"), |
| 9706 | MockRead(SYNCHRONOUS, OK) |
| 9707 | }; |
| 9708 | |
| 9709 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9710 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9711 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9712 | |
| 9713 | TestCompletionCallback callback; |
| 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] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9717 | |
| 9718 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9719 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9720 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9721 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9722 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9723 | |
| 9724 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9725 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9726 | TestLoadTimingNotReused(load_timing_info, |
| 9727 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9728 | |
| 9729 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9730 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9731 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9732 | EXPECT_EQ("Payload", response_text); |
| 9733 | } |
| 9734 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9735 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9736 | HttpRequestInfo request; |
| 9737 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9738 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9739 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 9740 | session_deps_.proxy_resolution_service = |
| 9741 | ProxyResolutionService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9742 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9743 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9744 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9745 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9746 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9747 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9748 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9749 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9750 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9751 | 0x05, // Version |
| 9752 | 0x01, // Command (CONNECT) |
| 9753 | 0x00, // Reserved. |
| 9754 | 0x03, // Address type (DOMAINNAME). |
| 9755 | 0x0F, // Length of domain (15) |
| 9756 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9757 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9758 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9759 | const char kSOCKS5OkResponse[] = |
| 9760 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9761 | |
| 9762 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9763 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9764 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9765 | MockWrite( |
| 9766 | "GET / HTTP/1.1\r\n" |
| 9767 | "Host: www.example.org\r\n" |
| 9768 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9769 | |
| 9770 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9771 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9772 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9773 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9774 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9775 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9776 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9777 | }; |
| 9778 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9779 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9780 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9781 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9782 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9783 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9784 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9785 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9786 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9787 | |
| 9788 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9789 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9790 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9791 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9792 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9793 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9794 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9795 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9796 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9797 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9798 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9799 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9800 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9801 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9802 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9803 | EXPECT_EQ("Payload", response_text); |
| 9804 | } |
| 9805 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9806 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9807 | HttpRequestInfo request; |
| 9808 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9809 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9810 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 9811 | session_deps_.proxy_resolution_service = |
| 9812 | ProxyResolutionService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9813 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9814 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9815 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9816 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9817 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9818 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9819 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9820 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9821 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9822 | 0x05, // Version |
| 9823 | 0x01, // Command (CONNECT) |
| 9824 | 0x00, // Reserved. |
| 9825 | 0x03, // Address type (DOMAINNAME). |
| 9826 | 0x0F, // Length of domain (15) |
| 9827 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9828 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9829 | }; |
| 9830 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9831 | const char kSOCKS5OkResponse[] = |
| 9832 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9833 | |
| 9834 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9835 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9836 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9837 | arraysize(kSOCKS5OkRequest)), |
| 9838 | MockWrite( |
| 9839 | "GET / HTTP/1.1\r\n" |
| 9840 | "Host: www.example.org\r\n" |
| 9841 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9842 | |
| 9843 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9844 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9845 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9846 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9847 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9848 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9849 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9850 | }; |
| 9851 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9852 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9853 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9854 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9855 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9856 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9857 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9858 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9859 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9860 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9861 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9862 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9863 | |
| 9864 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9865 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9866 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9867 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9868 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9869 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9870 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9871 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9872 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9873 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9874 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9875 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9876 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9877 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9878 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9879 | EXPECT_EQ("Payload", response_text); |
| 9880 | } |
| 9881 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9882 | namespace { |
| 9883 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9884 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9885 | |
| 9886 | struct GroupNameTest { |
| 9887 | std::string proxy_server; |
| 9888 | std::string url; |
| 9889 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9890 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9891 | }; |
| 9892 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9893 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9894 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9895 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9896 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9897 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9898 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9899 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9900 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 9901 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9902 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9903 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9904 | |
| 9905 | return session; |
| 9906 | } |
| 9907 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9908 | int GroupNameTransactionHelper(const std::string& url, |
| 9909 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9910 | HttpRequestInfo request; |
| 9911 | request.method = "GET"; |
| 9912 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9913 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9914 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9916 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9917 | |
| 9918 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9919 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9920 | } |
| 9921 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9922 | } // namespace |
| 9923 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9924 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9925 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9926 | { |
| 9927 | "", // unused |
| 9928 | "http://www.example.org/direct", |
| 9929 | "www.example.org:80", |
| 9930 | false, |
| 9931 | }, |
| 9932 | { |
| 9933 | "", // unused |
| 9934 | "http://[2001:1418:13:1::25]/direct", |
| 9935 | "[2001:1418:13:1::25]:80", |
| 9936 | false, |
| 9937 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9938 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9939 | // SSL Tests |
| 9940 | { |
| 9941 | "", // unused |
| 9942 | "https://www.example.org/direct_ssl", |
| 9943 | "ssl/www.example.org:443", |
| 9944 | true, |
| 9945 | }, |
| 9946 | { |
| 9947 | "", // unused |
| 9948 | "https://[2001:1418:13:1::25]/direct", |
| 9949 | "ssl/[2001:1418:13:1::25]:443", |
| 9950 | true, |
| 9951 | }, |
| 9952 | { |
| 9953 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9954 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9955 | "ssl/host.with.alternate:443", |
| 9956 | true, |
| 9957 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9958 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9959 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9960 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 9961 | session_deps_.proxy_resolution_service = |
| 9962 | ProxyResolutionService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9963 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9964 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9965 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9966 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9967 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9968 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9969 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9970 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9971 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9972 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9973 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9974 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9975 | |
| 9976 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9977 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 9978 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9979 | EXPECT_EQ(tests[i].expected_group_name, |
| 9980 | ssl_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 9981 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9982 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9983 | transport_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 9984 | } |
| 9985 | // When SSL proxy is in use, socket must be requested from |ssl_conn_pool|. |
| 9986 | EXPECT_EQ(tests[i].ssl, ssl_conn_pool->socket_requested()); |
| 9987 | // When SSL proxy is not in use, socket must be requested from |
| 9988 | // |transport_conn_pool|. |
| 9989 | EXPECT_EQ(!tests[i].ssl, transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9990 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9991 | } |
| 9992 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9993 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9994 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9995 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 9996 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 9997 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9998 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9999 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10000 | // SSL Tests |
| 10001 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10002 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 10003 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10004 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10005 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10006 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10007 | "http_proxy", "https://host.with.alternate/direct", |
| 10008 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10009 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 10010 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10011 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10012 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 10013 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10014 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10015 | }; |
| 10016 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10017 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 10018 | session_deps_.proxy_resolution_service = |
| 10019 | ProxyResolutionService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10020 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10021 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10022 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10023 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10024 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10025 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10026 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10027 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10028 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10029 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10030 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10031 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 10032 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 10033 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10034 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10035 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10036 | |
| 10037 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10038 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10039 | if (tests[i].ssl) |
| 10040 | EXPECT_EQ(tests[i].expected_group_name, |
| 10041 | ssl_conn_pool->last_group_name_received()); |
| 10042 | else |
| 10043 | EXPECT_EQ(tests[i].expected_group_name, |
| 10044 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10045 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10046 | } |
| 10047 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10048 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10049 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10050 | { |
| 10051 | "socks4://socks_proxy:1080", |
| 10052 | "http://www.example.org/socks4_direct", |
| 10053 | "socks4/www.example.org:80", |
| 10054 | false, |
| 10055 | }, |
| 10056 | { |
| 10057 | "socks5://socks_proxy:1080", |
| 10058 | "http://www.example.org/socks5_direct", |
| 10059 | "socks5/www.example.org:80", |
| 10060 | false, |
| 10061 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10062 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10063 | // SSL Tests |
| 10064 | { |
| 10065 | "socks4://socks_proxy:1080", |
| 10066 | "https://www.example.org/socks4_ssl", |
| 10067 | "socks4/ssl/www.example.org:443", |
| 10068 | true, |
| 10069 | }, |
| 10070 | { |
| 10071 | "socks5://socks_proxy:1080", |
| 10072 | "https://www.example.org/socks5_ssl", |
| 10073 | "socks5/ssl/www.example.org:443", |
| 10074 | true, |
| 10075 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10076 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10077 | { |
| 10078 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10079 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10080 | "socks4/ssl/host.with.alternate:443", |
| 10081 | true, |
| 10082 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10083 | }; |
| 10084 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10085 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 10086 | session_deps_.proxy_resolution_service = |
| 10087 | ProxyResolutionService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10088 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10089 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 10090 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10091 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10092 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10093 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10094 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10095 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10096 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10097 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10098 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10099 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 10100 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 10101 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10102 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10103 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10104 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10105 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10106 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10107 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10108 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10109 | if (tests[i].ssl) |
| 10110 | EXPECT_EQ(tests[i].expected_group_name, |
| 10111 | ssl_conn_pool->last_group_name_received()); |
| 10112 | else |
| 10113 | EXPECT_EQ(tests[i].expected_group_name, |
| 10114 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10115 | } |
| 10116 | } |
| 10117 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10118 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10119 | HttpRequestInfo request; |
| 10120 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10121 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10122 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 10123 | session_deps_.proxy_resolution_service = |
| 10124 | ProxyResolutionService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10125 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 10126 | // This simulates failure resolving all hostnames; that means we will fail |
| 10127 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10128 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10129 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10130 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10131 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10133 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10134 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10135 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10136 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10137 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10138 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10139 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10140 | } |
| 10141 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10142 | // Base test to make sure that when the load flags for a request specify to |
| 10143 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10144 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10145 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10146 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10147 | HttpRequestInfo request_info; |
| 10148 | request_info.method = "GET"; |
| 10149 | request_info.load_flags = load_flags; |
| 10150 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10151 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 10152 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10153 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10154 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10155 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10156 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10157 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10158 | // 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] | 10159 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10160 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10161 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10162 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10163 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10164 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10165 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10166 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10167 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10168 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10169 | |
| 10170 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 10171 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10172 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10173 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10174 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10175 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10176 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10177 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10178 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10179 | // 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] | 10180 | // we can tell if the next lookup hit the cache, or the "network". |
| 10181 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10182 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10183 | |
| 10184 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 10185 | // 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] | 10186 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10187 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10188 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10189 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10190 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10191 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10192 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10193 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10194 | |
| 10195 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10196 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10197 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10198 | } |
| 10199 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10200 | // There are multiple load flags that should trigger the host cache bypass. |
| 10201 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10202 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10203 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 10204 | } |
| 10205 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10206 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10207 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 10208 | } |
| 10209 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10210 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10211 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 10212 | } |
| 10213 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10214 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10215 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10216 | HttpRequestInfo request; |
| 10217 | request.method = "GET"; |
| 10218 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10219 | |
| 10220 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10221 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10222 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10223 | StaticSocketDataProvider data(NULL, 0, |
| 10224 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10225 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10226 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10228 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10229 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10230 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10231 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10232 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10233 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10234 | |
| 10235 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10236 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10237 | |
| 10238 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10239 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10240 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10241 | } |
| 10242 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10243 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10244 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10245 | HttpRequestInfo request; |
| 10246 | request.method = "GET"; |
| 10247 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10248 | |
| 10249 | MockRead data_reads[] = { |
| 10250 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10251 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10252 | }; |
| 10253 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10254 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10255 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10256 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10257 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10258 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10259 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10260 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10261 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10262 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10263 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10264 | |
| 10265 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10266 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10267 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10268 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10269 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10270 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10271 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10272 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10273 | |
| 10274 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10275 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10276 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10277 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10278 | |
| 10279 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10280 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10281 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10282 | } |
| 10283 | |
| 10284 | // Make sure that a dropped connection while draining the body for auth |
| 10285 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10286 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10287 | HttpRequestInfo request; |
| 10288 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10289 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10290 | |
| 10291 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10292 | MockWrite( |
| 10293 | "GET / HTTP/1.1\r\n" |
| 10294 | "Host: www.example.org\r\n" |
| 10295 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10296 | }; |
| 10297 | |
| 10298 | MockRead data_reads1[] = { |
| 10299 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 10300 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10301 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10302 | MockRead("Content-Length: 14\r\n\r\n"), |
| 10303 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10304 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10305 | }; |
| 10306 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10307 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10308 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10309 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10310 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10311 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10312 | // be issuing -- the final header line contains the credentials. |
| 10313 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10314 | MockWrite( |
| 10315 | "GET / HTTP/1.1\r\n" |
| 10316 | "Host: www.example.org\r\n" |
| 10317 | "Connection: keep-alive\r\n" |
| 10318 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10319 | }; |
| 10320 | |
| 10321 | // Lastly, the server responds with the actual content. |
| 10322 | MockRead data_reads2[] = { |
| 10323 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10324 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10325 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10326 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10327 | }; |
| 10328 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10329 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10330 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10331 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10332 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10333 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10334 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10335 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10336 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10337 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10338 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10339 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10340 | |
| 10341 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10342 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10343 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10344 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10345 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10346 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10347 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10348 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10349 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10350 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10351 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10352 | |
| 10353 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10354 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10355 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10356 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10357 | ASSERT_TRUE(response); |
| 10358 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10359 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10360 | } |
| 10361 | |
| 10362 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10363 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 10364 | session_deps_.proxy_resolution_service = |
| 10365 | ProxyResolutionService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10366 | |
| 10367 | HttpRequestInfo request; |
| 10368 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10369 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10370 | |
| 10371 | MockRead proxy_reads[] = { |
| 10372 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10373 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10374 | }; |
| 10375 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10376 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10377 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10378 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10379 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10380 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10381 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10382 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10383 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10384 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10385 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10386 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10387 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10388 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10389 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10390 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10391 | |
| 10392 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10393 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10394 | } |
| 10395 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10396 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10397 | HttpRequestInfo request; |
| 10398 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10399 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10400 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10401 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10402 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10403 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10404 | MockRead data_reads[] = { |
| 10405 | 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] | 10406 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10407 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10408 | |
| 10409 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10410 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10411 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10412 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10413 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10414 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10415 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10416 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10417 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10418 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10419 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10420 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10421 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10422 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10423 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10424 | |
| 10425 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10426 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10427 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10428 | } |
| 10429 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10430 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10431 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10432 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10433 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10434 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10435 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10436 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10437 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10438 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10439 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10440 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10441 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10442 | |
| 10443 | HttpRequestInfo request; |
| 10444 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10445 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10446 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10447 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10448 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10449 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10450 | |
| 10451 | MockRead data_reads[] = { |
| 10452 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10453 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10454 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10455 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10456 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10457 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10458 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10459 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10460 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10461 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10462 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10463 | |
| 10464 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10465 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10466 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10467 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10468 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10469 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10470 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10471 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10472 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10473 | } |
| 10474 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10475 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10476 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10477 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10478 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10479 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10480 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10481 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10482 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10483 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10484 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10485 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10486 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10487 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10488 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10489 | |
| 10490 | HttpRequestInfo request; |
| 10491 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10492 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10493 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10494 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10495 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10496 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10497 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10498 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10499 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10500 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10501 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10502 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10503 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10504 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10505 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10506 | |
| 10507 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10508 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10509 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10510 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10511 | } |
| 10512 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10513 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10514 | class FakeUploadElementReader : public UploadElementReader { |
| 10515 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 10516 | FakeUploadElementReader() = default; |
| 10517 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10518 | |
| 10519 | const CompletionCallback& callback() const { return callback_; } |
| 10520 | |
| 10521 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10522 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10523 | callback_ = callback; |
| 10524 | return ERR_IO_PENDING; |
| 10525 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10526 | uint64_t GetContentLength() const override { return 0; } |
| 10527 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10528 | int Read(IOBuffer* buf, |
| 10529 | int buf_length, |
| 10530 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10531 | return ERR_FAILED; |
| 10532 | } |
| 10533 | |
| 10534 | private: |
| 10535 | CompletionCallback callback_; |
| 10536 | }; |
| 10537 | |
| 10538 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10539 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10540 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10541 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10542 | |
| 10543 | HttpRequestInfo request; |
| 10544 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10545 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10546 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10547 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10548 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10549 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10550 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10551 | |
| 10552 | StaticSocketDataProvider data; |
| 10553 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10554 | |
| 10555 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10556 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10557 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10558 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10559 | |
| 10560 | // Transaction is pending on request body initialization. |
| 10561 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 10562 | |
| 10563 | // Return Init()'s result after the transaction gets destroyed. |
| 10564 | trans.reset(); |
| 10565 | fake_reader->callback().Run(OK); // Should not crash. |
| 10566 | } |
| 10567 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10568 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10569 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10570 | HttpRequestInfo request; |
| 10571 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10572 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10573 | |
| 10574 | // First transaction will request a resource and receive a Basic challenge |
| 10575 | // with realm="first_realm". |
| 10576 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10577 | MockWrite( |
| 10578 | "GET / HTTP/1.1\r\n" |
| 10579 | "Host: www.example.org\r\n" |
| 10580 | "Connection: keep-alive\r\n" |
| 10581 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10582 | }; |
| 10583 | MockRead data_reads1[] = { |
| 10584 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10585 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10586 | "\r\n"), |
| 10587 | }; |
| 10588 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10589 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10590 | // for first_realm. The server will reject and provide a challenge with |
| 10591 | // second_realm. |
| 10592 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10593 | MockWrite( |
| 10594 | "GET / HTTP/1.1\r\n" |
| 10595 | "Host: www.example.org\r\n" |
| 10596 | "Connection: keep-alive\r\n" |
| 10597 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10598 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10599 | }; |
| 10600 | MockRead data_reads2[] = { |
| 10601 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10602 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10603 | "\r\n"), |
| 10604 | }; |
| 10605 | |
| 10606 | // This again fails, and goes back to first_realm. Make sure that the |
| 10607 | // entry is removed from cache. |
| 10608 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10609 | MockWrite( |
| 10610 | "GET / HTTP/1.1\r\n" |
| 10611 | "Host: www.example.org\r\n" |
| 10612 | "Connection: keep-alive\r\n" |
| 10613 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10614 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10615 | }; |
| 10616 | MockRead data_reads3[] = { |
| 10617 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10618 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10619 | "\r\n"), |
| 10620 | }; |
| 10621 | |
| 10622 | // Try one last time (with the correct password) and get the resource. |
| 10623 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10624 | MockWrite( |
| 10625 | "GET / HTTP/1.1\r\n" |
| 10626 | "Host: www.example.org\r\n" |
| 10627 | "Connection: keep-alive\r\n" |
| 10628 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10629 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10630 | }; |
| 10631 | MockRead data_reads4[] = { |
| 10632 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10633 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10634 | "Content-Length: 5\r\n" |
| 10635 | "\r\n" |
| 10636 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10637 | }; |
| 10638 | |
| 10639 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10640 | data_writes1, arraysize(data_writes1)); |
| 10641 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10642 | data_writes2, arraysize(data_writes2)); |
| 10643 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 10644 | data_writes3, arraysize(data_writes3)); |
| 10645 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 10646 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10647 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10648 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10649 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10650 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10651 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10652 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10653 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10654 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10656 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10657 | // Issue the first request with Authorize headers. There should be a |
| 10658 | // password prompt for first_realm waiting to be filled in after the |
| 10659 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10660 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10661 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10662 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10663 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10664 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10665 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10666 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10667 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10668 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10669 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10670 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10671 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10672 | |
| 10673 | // Issue the second request with an incorrect password. There should be a |
| 10674 | // password prompt for second_realm waiting to be filled in after the |
| 10675 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10676 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10677 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10678 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10679 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10680 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10681 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10682 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10683 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10684 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10685 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10686 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10687 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10688 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10689 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10690 | |
| 10691 | // Issue the third request with another incorrect password. There should be |
| 10692 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10693 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10694 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10695 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10696 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10697 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10698 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10699 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10700 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10701 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10702 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10703 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10704 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10705 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10706 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10707 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10708 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10709 | |
| 10710 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10711 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10712 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10713 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10714 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10715 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10716 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10717 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10718 | ASSERT_TRUE(response); |
| 10719 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10720 | } |
| 10721 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10722 | // Regression test for https://crbug.com/754395. |
| 10723 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 10724 | MockRead data_reads[] = { |
| 10725 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10726 | MockRead(kAlternativeServiceHttpHeader), |
| 10727 | MockRead("\r\n"), |
| 10728 | MockRead("hello world"), |
| 10729 | MockRead(SYNCHRONOUS, OK), |
| 10730 | }; |
| 10731 | |
| 10732 | HttpRequestInfo request; |
| 10733 | request.method = "GET"; |
| 10734 | request.url = GURL("https://www.example.org/"); |
| 10735 | |
| 10736 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10737 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10738 | |
| 10739 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10740 | ssl.ssl_info.cert = |
| 10741 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10742 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 10743 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10744 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10745 | |
| 10746 | TestCompletionCallback callback; |
| 10747 | |
| 10748 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10749 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10750 | |
| 10751 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10752 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10753 | |
| 10754 | url::SchemeHostPort test_server(request.url); |
| 10755 | HttpServerProperties* http_server_properties = |
| 10756 | session->http_server_properties(); |
| 10757 | EXPECT_TRUE( |
| 10758 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10759 | |
| 10760 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 10761 | |
| 10762 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10763 | ASSERT_TRUE(response); |
| 10764 | ASSERT_TRUE(response->headers); |
| 10765 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10766 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10767 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 10768 | |
| 10769 | std::string response_data; |
| 10770 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 10771 | EXPECT_EQ("hello world", response_data); |
| 10772 | |
| 10773 | EXPECT_TRUE( |
| 10774 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10775 | } |
| 10776 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10777 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10778 | MockRead data_reads[] = { |
| 10779 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10780 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10781 | MockRead("\r\n"), |
| 10782 | MockRead("hello world"), |
| 10783 | MockRead(SYNCHRONOUS, OK), |
| 10784 | }; |
| 10785 | |
| 10786 | HttpRequestInfo request; |
| 10787 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10788 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10789 | |
| 10790 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10791 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10792 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10793 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10794 | ssl.ssl_info.cert = |
| 10795 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10796 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10797 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10798 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10799 | TestCompletionCallback callback; |
| 10800 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10801 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10802 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10803 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10804 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10805 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10806 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10807 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10808 | HttpServerProperties* http_server_properties = |
| 10809 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10810 | EXPECT_TRUE( |
| 10811 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10812 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10813 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10814 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10815 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10816 | ASSERT_TRUE(response); |
| 10817 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10818 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10819 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10820 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10821 | |
| 10822 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10823 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10824 | EXPECT_EQ("hello world", response_data); |
| 10825 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10826 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10827 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10828 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10829 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 10830 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10831 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10832 | } |
| 10833 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10834 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10835 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10836 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10837 | MockRead data_reads[] = { |
| 10838 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10839 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10840 | MockRead("\r\n"), |
| 10841 | MockRead("hello world"), |
| 10842 | MockRead(SYNCHRONOUS, OK), |
| 10843 | }; |
| 10844 | |
| 10845 | HttpRequestInfo request; |
| 10846 | request.method = "GET"; |
| 10847 | request.url = GURL("http://www.example.org/"); |
| 10848 | request.load_flags = 0; |
| 10849 | |
| 10850 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10851 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10852 | |
| 10853 | TestCompletionCallback callback; |
| 10854 | |
| 10855 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10856 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10857 | |
| 10858 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10859 | HttpServerProperties* http_server_properties = |
| 10860 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10861 | EXPECT_TRUE( |
| 10862 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10863 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10864 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10866 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10867 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10868 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10869 | ASSERT_TRUE(response); |
| 10870 | ASSERT_TRUE(response->headers); |
| 10871 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10872 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10873 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10874 | |
| 10875 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10876 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10877 | EXPECT_EQ("hello world", response_data); |
| 10878 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10879 | EXPECT_TRUE( |
| 10880 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10881 | } |
| 10882 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10883 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10884 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10885 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10886 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10887 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10888 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10889 | HttpRequestInfo request; |
| 10890 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10891 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10892 | request.load_flags = 0; |
| 10893 | |
| 10894 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10895 | StaticSocketDataProvider first_data; |
| 10896 | first_data.set_connect_data(mock_connect); |
| 10897 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10898 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10899 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10901 | |
| 10902 | MockRead data_reads[] = { |
| 10903 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10904 | MockRead(ASYNC, OK), |
| 10905 | }; |
| 10906 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10907 | 0); |
| 10908 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10909 | |
| 10910 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10911 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10912 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10913 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10914 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10915 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10916 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10917 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10918 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10919 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10920 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10921 | TestCompletionCallback callback; |
| 10922 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10923 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10924 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10925 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10926 | } |
| 10927 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10928 | // Regression test for https://crbug.com/615497: |
| 10929 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10930 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10931 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10932 | HttpRequestInfo request; |
| 10933 | request.method = "GET"; |
| 10934 | request.url = GURL("http://www.example.org/"); |
| 10935 | request.load_flags = 0; |
| 10936 | |
| 10937 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10938 | StaticSocketDataProvider first_data; |
| 10939 | first_data.set_connect_data(mock_connect); |
| 10940 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10941 | |
| 10942 | MockRead data_reads[] = { |
| 10943 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10944 | MockRead(ASYNC, OK), |
| 10945 | }; |
| 10946 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10947 | 0); |
| 10948 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10949 | |
| 10950 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10951 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10952 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10953 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10954 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10955 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10956 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10957 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10958 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10959 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10960 | TestCompletionCallback callback; |
| 10961 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10962 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10963 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10964 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10965 | } |
| 10966 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10967 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10968 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10969 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10970 | HttpServerProperties* http_server_properties = |
| 10971 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10972 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10973 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10974 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10975 | http_server_properties->SetQuicAlternativeService( |
| 10976 | test_server, alternative_service, expiration, |
| 10977 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10978 | EXPECT_EQ( |
| 10979 | 1u, |
| 10980 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10981 | |
| 10982 | // Send a clear header. |
| 10983 | MockRead data_reads[] = { |
| 10984 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10985 | MockRead("Alt-Svc: clear\r\n"), |
| 10986 | MockRead("\r\n"), |
| 10987 | MockRead("hello world"), |
| 10988 | MockRead(SYNCHRONOUS, OK), |
| 10989 | }; |
| 10990 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10991 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10992 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10993 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10994 | ssl.ssl_info.cert = |
| 10995 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10996 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10997 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10998 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10999 | HttpRequestInfo request; |
| 11000 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11001 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11002 | |
| 11003 | TestCompletionCallback callback; |
| 11004 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11005 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11006 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11007 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11008 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11009 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11010 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11011 | ASSERT_TRUE(response); |
| 11012 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11013 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11014 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11015 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11016 | |
| 11017 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11018 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11019 | EXPECT_EQ("hello world", response_data); |
| 11020 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11021 | EXPECT_TRUE( |
| 11022 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11023 | } |
| 11024 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11025 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11026 | MockRead data_reads[] = { |
| 11027 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11028 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 11029 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11030 | MockRead("hello world"), |
| 11031 | MockRead(SYNCHRONOUS, OK), |
| 11032 | }; |
| 11033 | |
| 11034 | HttpRequestInfo request; |
| 11035 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11036 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11037 | |
| 11038 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11039 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11040 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11041 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11042 | ssl.ssl_info.cert = |
| 11043 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11044 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11045 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11046 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11047 | TestCompletionCallback callback; |
| 11048 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11049 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11050 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11051 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11052 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11053 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11054 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11055 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11056 | HttpServerProperties* http_server_properties = |
| 11057 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11058 | EXPECT_TRUE( |
| 11059 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11060 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11061 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11062 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11063 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11064 | ASSERT_TRUE(response); |
| 11065 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11066 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11067 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11068 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11069 | |
| 11070 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11071 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11072 | EXPECT_EQ("hello world", response_data); |
| 11073 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11074 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11075 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11076 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 11077 | |
| 11078 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 11079 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11080 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11081 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 11082 | 1234); |
| 11083 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11084 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11085 | } |
| 11086 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11087 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11088 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11089 | HostPortPair alternative("alternative.example.org", 443); |
| 11090 | std::string origin_url = "https://origin.example.org:443"; |
| 11091 | std::string alternative_url = "https://alternative.example.org:443"; |
| 11092 | |
| 11093 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 11094 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11095 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11096 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11097 | |
| 11098 | // HTTP/1.1 data for request. |
| 11099 | MockWrite http_writes[] = { |
| 11100 | MockWrite("GET / HTTP/1.1\r\n" |
| 11101 | "Host: alternative.example.org\r\n" |
| 11102 | "Connection: keep-alive\r\n\r\n"), |
| 11103 | }; |
| 11104 | |
| 11105 | MockRead http_reads[] = { |
| 11106 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11107 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11108 | "Content-Length: 40\r\n\r\n" |
| 11109 | "first HTTP/1.1 response from alternative"), |
| 11110 | }; |
| 11111 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11112 | http_writes, arraysize(http_writes)); |
| 11113 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11114 | |
| 11115 | StaticSocketDataProvider data_refused; |
| 11116 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11117 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11118 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11119 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11120 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11121 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11122 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11123 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11124 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11125 | http_server_properties->SetQuicAlternativeService( |
| 11126 | server, alternative_service, expiration, |
| 11127 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11128 | // Mark the QUIC alternative service as broken. |
| 11129 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 11130 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11131 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11132 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11133 | request.method = "GET"; |
| 11134 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11135 | TestCompletionCallback callback; |
| 11136 | NetErrorDetails details; |
| 11137 | EXPECT_FALSE(details.quic_broken); |
| 11138 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11139 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11140 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11141 | EXPECT_TRUE(details.quic_broken); |
| 11142 | } |
| 11143 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11144 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11145 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11146 | HostPortPair alternative1("alternative1.example.org", 443); |
| 11147 | HostPortPair alternative2("alternative2.example.org", 443); |
| 11148 | std::string origin_url = "https://origin.example.org:443"; |
| 11149 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 11150 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 11151 | |
| 11152 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 11153 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11154 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11155 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11156 | |
| 11157 | // HTTP/1.1 data for request. |
| 11158 | MockWrite http_writes[] = { |
| 11159 | MockWrite("GET / HTTP/1.1\r\n" |
| 11160 | "Host: alternative1.example.org\r\n" |
| 11161 | "Connection: keep-alive\r\n\r\n"), |
| 11162 | }; |
| 11163 | |
| 11164 | MockRead http_reads[] = { |
| 11165 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11166 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11167 | "Content-Length: 40\r\n\r\n" |
| 11168 | "first HTTP/1.1 response from alternative1"), |
| 11169 | }; |
| 11170 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11171 | http_writes, arraysize(http_writes)); |
| 11172 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11173 | |
| 11174 | StaticSocketDataProvider data_refused; |
| 11175 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11176 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11177 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11179 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11180 | session->http_server_properties(); |
| 11181 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11182 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11183 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 11184 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11185 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11186 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11187 | alternative_service_info_vector.push_back( |
| 11188 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11189 | alternative_service1, expiration, |
| 11190 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11191 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11192 | alternative_service_info_vector.push_back( |
| 11193 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11194 | alternative_service2, expiration, |
| 11195 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11196 | |
| 11197 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11198 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11199 | |
| 11200 | // Mark one of the QUIC alternative service as broken. |
| 11201 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11202 | EXPECT_EQ(2u, |
| 11203 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11204 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11205 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11206 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11207 | request.method = "GET"; |
| 11208 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11209 | TestCompletionCallback callback; |
| 11210 | NetErrorDetails details; |
| 11211 | EXPECT_FALSE(details.quic_broken); |
| 11212 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11213 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11214 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11215 | EXPECT_FALSE(details.quic_broken); |
| 11216 | } |
| 11217 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11218 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11219 | HttpRequestInfo request; |
| 11220 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11221 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11222 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11223 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11224 | StaticSocketDataProvider first_data; |
| 11225 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11226 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11227 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11228 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11229 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11230 | |
| 11231 | MockRead data_reads[] = { |
| 11232 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11233 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11234 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11235 | }; |
| 11236 | StaticSocketDataProvider second_data( |
| 11237 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11238 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11239 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11240 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11241 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11242 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11243 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11244 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11245 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 11246 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11247 | // Port is ignored by MockConnect anyway. |
| 11248 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11249 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11250 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11251 | http_server_properties->SetHttp2AlternativeService( |
| 11252 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11253 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11254 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11255 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11256 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11257 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11258 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11259 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11261 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11262 | ASSERT_TRUE(response); |
| 11263 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11264 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11265 | |
| 11266 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11267 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11268 | EXPECT_EQ("hello world", response_data); |
| 11269 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11270 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 11271 | http_server_properties->GetAlternativeServiceInfos(server); |
| 11272 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11273 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11274 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11275 | EXPECT_TRUE( |
| 11276 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11277 | } |
| 11278 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11279 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11280 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11281 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11282 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11283 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11284 | HttpRequestInfo restricted_port_request; |
| 11285 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11286 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11287 | restricted_port_request.load_flags = 0; |
| 11288 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11289 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11290 | StaticSocketDataProvider first_data; |
| 11291 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11292 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11293 | |
| 11294 | MockRead data_reads[] = { |
| 11295 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11296 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11297 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11298 | }; |
| 11299 | StaticSocketDataProvider second_data( |
| 11300 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11301 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11302 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11303 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11304 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11305 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11306 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11307 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11308 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11309 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11310 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11311 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11312 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11313 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11314 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11315 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11316 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11317 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11318 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11319 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11320 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11321 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11322 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11323 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11324 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11325 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11326 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11327 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11328 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 11329 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 11330 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11331 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11332 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11333 | |
| 11334 | HttpRequestInfo restricted_port_request; |
| 11335 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11336 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11337 | restricted_port_request.load_flags = 0; |
| 11338 | |
| 11339 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11340 | StaticSocketDataProvider first_data; |
| 11341 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11342 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11343 | |
| 11344 | MockRead data_reads[] = { |
| 11345 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11346 | MockRead("hello world"), |
| 11347 | MockRead(ASYNC, OK), |
| 11348 | }; |
| 11349 | StaticSocketDataProvider second_data( |
| 11350 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11351 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11352 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11353 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11354 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11355 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11356 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11357 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11358 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11359 | session->http_server_properties(); |
| 11360 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11361 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11362 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11363 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11364 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11365 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11366 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11367 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11368 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11369 | TestCompletionCallback callback; |
| 11370 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11371 | EXPECT_EQ(ERR_IO_PENDING, |
| 11372 | trans.Start(&restricted_port_request, callback.callback(), |
| 11373 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11374 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11375 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11376 | } |
| 11377 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11378 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11379 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11380 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11381 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11382 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11383 | HttpRequestInfo restricted_port_request; |
| 11384 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11385 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11386 | restricted_port_request.load_flags = 0; |
| 11387 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11388 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11389 | StaticSocketDataProvider first_data; |
| 11390 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11391 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11392 | |
| 11393 | MockRead data_reads[] = { |
| 11394 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11395 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11396 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11397 | }; |
| 11398 | StaticSocketDataProvider second_data( |
| 11399 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11400 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11401 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11402 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11403 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11406 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11407 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11408 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11409 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11410 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11411 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11412 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11413 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11414 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11415 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11416 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11417 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11418 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11419 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11420 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11421 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11422 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11423 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11424 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11425 | } |
| 11426 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11427 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11428 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11429 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11430 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11431 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11432 | HttpRequestInfo unrestricted_port_request; |
| 11433 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11434 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11435 | unrestricted_port_request.load_flags = 0; |
| 11436 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11437 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11438 | StaticSocketDataProvider first_data; |
| 11439 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11440 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11441 | |
| 11442 | MockRead data_reads[] = { |
| 11443 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11444 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11445 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11446 | }; |
| 11447 | StaticSocketDataProvider second_data( |
| 11448 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11449 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11450 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11451 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11452 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11453 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11454 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11455 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11456 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11457 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11458 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11459 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11460 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11461 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11462 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11463 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11464 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11466 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11467 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11468 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11469 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11470 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11471 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11472 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11473 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11474 | } |
| 11475 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11476 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11477 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11478 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11479 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11480 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11481 | HttpRequestInfo unrestricted_port_request; |
| 11482 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11483 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11484 | unrestricted_port_request.load_flags = 0; |
| 11485 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11486 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11487 | StaticSocketDataProvider first_data; |
| 11488 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11489 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11490 | |
| 11491 | MockRead data_reads[] = { |
| 11492 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11493 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11494 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11495 | }; |
| 11496 | StaticSocketDataProvider second_data( |
| 11497 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11498 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11499 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11500 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11501 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11502 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11503 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11504 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11505 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11506 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11507 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11508 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11509 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11510 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11511 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11512 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11513 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11514 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11515 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11516 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11517 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11518 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11519 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11520 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11521 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11522 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11523 | } |
| 11524 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11525 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11526 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 11527 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11528 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11529 | HttpRequestInfo request; |
| 11530 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11531 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11532 | |
| 11533 | // The alternate protocol request will error out before we attempt to connect, |
| 11534 | // so only the standard HTTP request will try to connect. |
| 11535 | MockRead data_reads[] = { |
| 11536 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11537 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11538 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11539 | }; |
| 11540 | StaticSocketDataProvider data( |
| 11541 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11542 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11543 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11544 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11545 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11546 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11547 | session->http_server_properties(); |
| 11548 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11549 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11550 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11551 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11552 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11553 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11555 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11556 | TestCompletionCallback callback; |
| 11557 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11558 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11559 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11560 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11561 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11562 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11563 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11564 | ASSERT_TRUE(response); |
| 11565 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11566 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11567 | |
| 11568 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11569 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11570 | EXPECT_EQ("hello world", response_data); |
| 11571 | } |
| 11572 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11573 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11574 | HttpRequestInfo request; |
| 11575 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11576 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11577 | |
| 11578 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11579 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11580 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11581 | MockRead("\r\n"), |
| 11582 | MockRead("hello world"), |
| 11583 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11584 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11585 | |
| 11586 | StaticSocketDataProvider first_transaction( |
| 11587 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11588 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11589 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11590 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11591 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11592 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11593 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11594 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11595 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11596 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11597 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11598 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11599 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11600 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11601 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11602 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11603 | }; |
| 11604 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11605 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11606 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11607 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11608 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11609 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11610 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11611 | NULL, 0, NULL, 0); |
| 11612 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11613 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11614 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11615 | &hanging_non_alternate_protocol_socket); |
| 11616 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11617 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11618 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11619 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11620 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11621 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11623 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11625 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11626 | |
| 11627 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11628 | ASSERT_TRUE(response); |
| 11629 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11630 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11631 | |
| 11632 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11633 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11634 | EXPECT_EQ("hello world", response_data); |
| 11635 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11636 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11637 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11638 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11639 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11641 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11642 | |
| 11643 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11644 | ASSERT_TRUE(response); |
| 11645 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11646 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11647 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11648 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11649 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11650 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11651 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11652 | } |
| 11653 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11654 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11655 | HttpRequestInfo request; |
| 11656 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11657 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11658 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11659 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11660 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11661 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11662 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11663 | MockRead("\r\n"), |
| 11664 | MockRead("hello world"), |
| 11665 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11666 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11667 | }; |
| 11668 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11669 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 11670 | 0); |
| 11671 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11672 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11673 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11674 | ssl_http11.ssl_info.cert = |
| 11675 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11676 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11677 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11678 | |
| 11679 | // Second transaction starts an alternative and a non-alternative Job. |
| 11680 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11681 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11682 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 11683 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11684 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11685 | |
| 11686 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 11687 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11688 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11689 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11690 | // Third transaction starts an alternative and a non-alternative job. |
| 11691 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11692 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11693 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11694 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11695 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11696 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11697 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11698 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11699 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11700 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11701 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11702 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11703 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11704 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11705 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 11706 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11707 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11708 | }; |
| 11709 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11710 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11711 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11712 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11713 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11714 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11715 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11716 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 11717 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 11718 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11719 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11720 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11721 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11722 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11723 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11724 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11725 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11726 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11727 | |
| 11728 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11729 | ASSERT_TRUE(response); |
| 11730 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11731 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11732 | |
| 11733 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11734 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11735 | EXPECT_EQ("hello world", response_data); |
| 11736 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11737 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11738 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11739 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11741 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11742 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11743 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11744 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11745 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11746 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11747 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11748 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11749 | |
| 11750 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11751 | ASSERT_TRUE(response); |
| 11752 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11753 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11754 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11755 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11756 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11757 | EXPECT_EQ("hello!", response_data); |
| 11758 | |
| 11759 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11760 | ASSERT_TRUE(response); |
| 11761 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11762 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11763 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11764 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11765 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11766 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11767 | } |
| 11768 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11769 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11770 | HttpRequestInfo request; |
| 11771 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11772 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11773 | |
| 11774 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11775 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11776 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11777 | MockRead("\r\n"), |
| 11778 | MockRead("hello world"), |
| 11779 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11780 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11781 | }; |
| 11782 | |
| 11783 | StaticSocketDataProvider first_transaction( |
| 11784 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11785 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11786 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11787 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11788 | ssl.ssl_info.cert = |
| 11789 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11790 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11791 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11792 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11793 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11794 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11795 | NULL, 0, NULL, 0); |
| 11796 | hanging_alternate_protocol_socket.set_connect_data( |
| 11797 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11798 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11799 | &hanging_alternate_protocol_socket); |
| 11800 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11801 | // 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] | 11802 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11803 | NULL, 0); |
| 11804 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11805 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11807 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11808 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11810 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11811 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11812 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11813 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11815 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11816 | |
| 11817 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11818 | ASSERT_TRUE(response); |
| 11819 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11820 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11821 | |
| 11822 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11823 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11824 | EXPECT_EQ("hello world", response_data); |
| 11825 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11826 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11827 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11828 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11829 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11831 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11832 | |
| 11833 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11834 | ASSERT_TRUE(response); |
| 11835 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11836 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11837 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11838 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11839 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11840 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11841 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11842 | } |
| 11843 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11844 | class CapturingProxyResolver : public ProxyResolver { |
| 11845 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11846 | CapturingProxyResolver() = default; |
| 11847 | ~CapturingProxyResolver() override = default; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11848 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11849 | int GetProxyForURL(const GURL& url, |
| 11850 | ProxyInfo* results, |
| 11851 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11852 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11853 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11854 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11855 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11856 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11857 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11858 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11859 | } |
| 11860 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11861 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11862 | |
| 11863 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11864 | std::vector<GURL> resolved_; |
| 11865 | |
| 11866 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11867 | }; |
| 11868 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11869 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11870 | public: |
| 11871 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11872 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11873 | |
| 11874 | int CreateProxyResolver( |
| 11875 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11876 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11877 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11878 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11879 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11880 | return OK; |
| 11881 | } |
| 11882 | |
| 11883 | private: |
| 11884 | ProxyResolver* resolver_; |
| 11885 | }; |
| 11886 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11887 | // Test that proxy is resolved using the origin url, |
| 11888 | // regardless of the alternative server. |
| 11889 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11890 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11891 | ProxyConfig proxy_config; |
| 11892 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11893 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11894 | auto proxy_config_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11895 | std::make_unique<ProxyConfigServiceFixed>(proxy_config); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11896 | |
| 11897 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11898 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11899 | &capturing_proxy_resolver); |
| 11900 | |
| 11901 | TestNetLog net_log; |
| 11902 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 11903 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11904 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11905 | &net_log); |
| 11906 | |
| 11907 | session_deps_.net_log = &net_log; |
| 11908 | |
| 11909 | // Configure alternative service with a hostname that is not bypassed by the |
| 11910 | // proxy. |
| 11911 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11912 | HttpServerProperties* http_server_properties = |
| 11913 | session->http_server_properties(); |
| 11914 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11915 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11916 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11917 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11918 | http_server_properties->SetHttp2AlternativeService( |
| 11919 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11920 | |
| 11921 | // Non-alternative job should hang. |
| 11922 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11923 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11924 | nullptr, 0); |
| 11925 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11926 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11927 | &hanging_alternate_protocol_socket); |
| 11928 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11929 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11930 | |
| 11931 | HttpRequestInfo request; |
| 11932 | request.method = "GET"; |
| 11933 | request.url = GURL("https://www.example.org/"); |
| 11934 | request.load_flags = 0; |
| 11935 | |
| 11936 | SpdySerializedFrame req( |
| 11937 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11938 | |
| 11939 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11940 | |
| 11941 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11942 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11943 | MockRead spdy_reads[] = { |
| 11944 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11945 | }; |
| 11946 | |
| 11947 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11948 | arraysize(spdy_writes)); |
| 11949 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11950 | |
| 11951 | TestCompletionCallback callback; |
| 11952 | |
| 11953 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11954 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11955 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11956 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11957 | |
| 11958 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11959 | ASSERT_TRUE(response); |
| 11960 | ASSERT_TRUE(response->headers); |
| 11961 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11962 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11963 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11964 | |
| 11965 | std::string response_data; |
| 11966 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11967 | EXPECT_EQ("hello!", response_data); |
| 11968 | |
| 11969 | // Origin host bypasses proxy, no resolution should have happened. |
| 11970 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11971 | } |
| 11972 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11973 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11974 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11975 | proxy_config.set_auto_detect(true); |
| 11976 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11977 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11978 | CapturingProxyResolver capturing_proxy_resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 11979 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11980 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
| 11981 | std::make_unique<CapturingProxyResolverFactory>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11982 | &capturing_proxy_resolver), |
| 11983 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11984 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11985 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11986 | |
| 11987 | HttpRequestInfo request; |
| 11988 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11989 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11990 | |
| 11991 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11992 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11993 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11994 | MockRead("\r\n"), |
| 11995 | MockRead("hello world"), |
| 11996 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11997 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11998 | }; |
| 11999 | |
| 12000 | StaticSocketDataProvider first_transaction( |
| 12001 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12002 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12003 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12004 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12005 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12006 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12007 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12008 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12009 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12010 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12011 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12012 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12013 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12014 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12015 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12016 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12017 | }; |
| 12018 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12019 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 12020 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12021 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12022 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12023 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12024 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 12025 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12026 | }; |
| 12027 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12028 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12029 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12030 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12031 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12032 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12033 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 12034 | NULL, 0, NULL, 0); |
| 12035 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12036 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12037 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12038 | &hanging_non_alternate_protocol_socket); |
| 12039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12040 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12041 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12042 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12043 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12044 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12045 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12046 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12047 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12048 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12049 | |
| 12050 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12051 | ASSERT_TRUE(response); |
| 12052 | ASSERT_TRUE(response->headers); |
| 12053 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 12054 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12055 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12056 | |
| 12057 | std::string response_data; |
| 12058 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 12059 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12060 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12061 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12062 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12063 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12064 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12066 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12067 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12068 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12069 | ASSERT_TRUE(response); |
| 12070 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12071 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12072 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12073 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12074 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12075 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12076 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12077 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 12078 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12079 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12080 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12081 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12082 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12083 | LoadTimingInfo load_timing_info; |
| 12084 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12085 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12086 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12087 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12088 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12089 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12090 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12091 | HttpRequestInfo request; |
| 12092 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12093 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12094 | |
| 12095 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12096 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12097 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12098 | MockRead("\r\n"), |
| 12099 | MockRead("hello world"), |
| 12100 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12101 | }; |
| 12102 | |
| 12103 | StaticSocketDataProvider first_transaction( |
| 12104 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12105 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12106 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12107 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12108 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12109 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12110 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12111 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12112 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12113 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12114 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12115 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12116 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12117 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12118 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12119 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12120 | }; |
| 12121 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12122 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12123 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12124 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12125 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 12126 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12127 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12128 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12129 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12130 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12131 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12132 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12133 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12134 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12135 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12136 | |
| 12137 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12138 | ASSERT_TRUE(response); |
| 12139 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12140 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12141 | |
| 12142 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12143 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12144 | EXPECT_EQ("hello world", response_data); |
| 12145 | |
| 12146 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12147 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12148 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 12149 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12150 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 12151 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 12152 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12153 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12154 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12155 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12156 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12157 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12158 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12159 | |
| 12160 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12161 | ASSERT_TRUE(response); |
| 12162 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12163 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12164 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12165 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12166 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12167 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12168 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12169 | } |
| 12170 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12171 | // GenerateAuthToken is a mighty big test. |
| 12172 | // It tests all permutation of GenerateAuthToken behavior: |
| 12173 | // - Synchronous and Asynchronous completion. |
| 12174 | // - OK or error on completion. |
| 12175 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 12176 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 12177 | // - Non-authenticating and authenticating backend. |
| 12178 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12179 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12180 | // problems generating an auth token for an authenticating proxy, we don't |
| 12181 | // need to test all permutations of the backend server). |
| 12182 | // |
| 12183 | // The test proceeds by going over each of the configuration cases, and |
| 12184 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 12185 | // specifies both the configuration for the test as well as the expectations |
| 12186 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12187 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12188 | static const char kServer[] = "http://www.example.com"; |
| 12189 | static const char kSecureServer[] = "https://www.example.com"; |
| 12190 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12191 | |
| 12192 | enum AuthTiming { |
| 12193 | AUTH_NONE, |
| 12194 | AUTH_SYNC, |
| 12195 | AUTH_ASYNC, |
| 12196 | }; |
| 12197 | |
| 12198 | const MockWrite kGet( |
| 12199 | "GET / HTTP/1.1\r\n" |
| 12200 | "Host: www.example.com\r\n" |
| 12201 | "Connection: keep-alive\r\n\r\n"); |
| 12202 | const MockWrite kGetProxy( |
| 12203 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12204 | "Host: www.example.com\r\n" |
| 12205 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12206 | const MockWrite kGetAuth( |
| 12207 | "GET / HTTP/1.1\r\n" |
| 12208 | "Host: www.example.com\r\n" |
| 12209 | "Connection: keep-alive\r\n" |
| 12210 | "Authorization: auth_token\r\n\r\n"); |
| 12211 | const MockWrite kGetProxyAuth( |
| 12212 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12213 | "Host: www.example.com\r\n" |
| 12214 | "Proxy-Connection: keep-alive\r\n" |
| 12215 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12216 | const MockWrite kGetAuthThroughProxy( |
| 12217 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12218 | "Host: www.example.com\r\n" |
| 12219 | "Proxy-Connection: keep-alive\r\n" |
| 12220 | "Authorization: auth_token\r\n\r\n"); |
| 12221 | const MockWrite kGetAuthWithProxyAuth( |
| 12222 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12223 | "Host: www.example.com\r\n" |
| 12224 | "Proxy-Connection: keep-alive\r\n" |
| 12225 | "Proxy-Authorization: auth_token\r\n" |
| 12226 | "Authorization: auth_token\r\n\r\n"); |
| 12227 | const MockWrite kConnect( |
| 12228 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12229 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12230 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12231 | const MockWrite kConnectProxyAuth( |
| 12232 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12233 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12234 | "Proxy-Connection: keep-alive\r\n" |
| 12235 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12236 | |
| 12237 | const MockRead kSuccess( |
| 12238 | "HTTP/1.1 200 OK\r\n" |
| 12239 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12240 | "Content-Length: 3\r\n\r\n" |
| 12241 | "Yes"); |
| 12242 | const MockRead kFailure( |
| 12243 | "Should not be called."); |
| 12244 | const MockRead kServerChallenge( |
| 12245 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12246 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12247 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12248 | "Content-Length: 14\r\n\r\n" |
| 12249 | "Unauthorized\r\n"); |
| 12250 | const MockRead kProxyChallenge( |
| 12251 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12252 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 12253 | "Proxy-Connection: close\r\n" |
| 12254 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12255 | "Content-Length: 14\r\n\r\n" |
| 12256 | "Unauthorized\r\n"); |
| 12257 | const MockRead kProxyConnected( |
| 12258 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 12259 | |
| 12260 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 12261 | // no constructors, but the C++ compiler on Windows warns about |
| 12262 | // unspecified data in compound literals. So, moved to using constructors, |
| 12263 | // and TestRound's created with the default constructor should not be used. |
| 12264 | struct TestRound { |
| 12265 | TestRound() |
| 12266 | : expected_rv(ERR_UNEXPECTED), |
| 12267 | extra_write(NULL), |
| 12268 | extra_read(NULL) { |
| 12269 | } |
| 12270 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12271 | int expected_rv_arg) |
| 12272 | : write(write_arg), |
| 12273 | read(read_arg), |
| 12274 | expected_rv(expected_rv_arg), |
| 12275 | extra_write(NULL), |
| 12276 | extra_read(NULL) { |
| 12277 | } |
| 12278 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12279 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 12280 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12281 | : write(write_arg), |
| 12282 | read(read_arg), |
| 12283 | expected_rv(expected_rv_arg), |
| 12284 | extra_write(extra_write_arg), |
| 12285 | extra_read(extra_read_arg) { |
| 12286 | } |
| 12287 | MockWrite write; |
| 12288 | MockRead read; |
| 12289 | int expected_rv; |
| 12290 | const MockWrite* extra_write; |
| 12291 | const MockRead* extra_read; |
| 12292 | }; |
| 12293 | |
| 12294 | static const int kNoSSL = 500; |
| 12295 | |
| 12296 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12297 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12298 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12299 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12300 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12301 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12302 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12303 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12304 | int num_auth_rounds; |
| 12305 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12306 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12307 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12308 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12309 | {__LINE__, |
| 12310 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12311 | AUTH_NONE, |
| 12312 | OK, |
| 12313 | kServer, |
| 12314 | AUTH_NONE, |
| 12315 | OK, |
| 12316 | 1, |
| 12317 | kNoSSL, |
| 12318 | {TestRound(kGet, kSuccess, OK)}}, |
| 12319 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12320 | {__LINE__, |
| 12321 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12322 | AUTH_NONE, |
| 12323 | OK, |
| 12324 | kServer, |
| 12325 | AUTH_SYNC, |
| 12326 | OK, |
| 12327 | 2, |
| 12328 | kNoSSL, |
| 12329 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12330 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12331 | {__LINE__, |
| 12332 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12333 | AUTH_NONE, |
| 12334 | OK, |
| 12335 | kServer, |
| 12336 | AUTH_SYNC, |
| 12337 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12338 | 3, |
| 12339 | kNoSSL, |
| 12340 | {TestRound(kGet, kServerChallenge, OK), |
| 12341 | TestRound(kGet, kServerChallenge, OK), |
| 12342 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12343 | {__LINE__, |
| 12344 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12345 | AUTH_NONE, |
| 12346 | OK, |
| 12347 | kServer, |
| 12348 | AUTH_SYNC, |
| 12349 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12350 | 2, |
| 12351 | kNoSSL, |
| 12352 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12353 | {__LINE__, |
| 12354 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12355 | AUTH_NONE, |
| 12356 | OK, |
| 12357 | kServer, |
| 12358 | AUTH_SYNC, |
| 12359 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 12360 | 2, |
| 12361 | kNoSSL, |
| 12362 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12363 | {__LINE__, |
| 12364 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12365 | AUTH_SYNC, |
| 12366 | ERR_FAILED, |
| 12367 | kServer, |
| 12368 | AUTH_NONE, |
| 12369 | OK, |
| 12370 | 2, |
| 12371 | kNoSSL, |
| 12372 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12373 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12374 | {__LINE__, |
| 12375 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12376 | AUTH_ASYNC, |
| 12377 | ERR_FAILED, |
| 12378 | kServer, |
| 12379 | AUTH_NONE, |
| 12380 | OK, |
| 12381 | 2, |
| 12382 | kNoSSL, |
| 12383 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12384 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12385 | {__LINE__, |
| 12386 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12387 | AUTH_NONE, |
| 12388 | OK, |
| 12389 | kServer, |
| 12390 | AUTH_SYNC, |
| 12391 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12392 | 2, |
| 12393 | kNoSSL, |
| 12394 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12395 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12396 | {__LINE__, |
| 12397 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12398 | AUTH_NONE, |
| 12399 | OK, |
| 12400 | kServer, |
| 12401 | AUTH_ASYNC, |
| 12402 | ERR_FAILED, |
| 12403 | 2, |
| 12404 | kNoSSL, |
| 12405 | {TestRound(kGet, kServerChallenge, OK), |
| 12406 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12407 | {__LINE__, |
| 12408 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12409 | AUTH_NONE, |
| 12410 | OK, |
| 12411 | kServer, |
| 12412 | AUTH_ASYNC, |
| 12413 | OK, |
| 12414 | 2, |
| 12415 | kNoSSL, |
| 12416 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12417 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12418 | {__LINE__, |
| 12419 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12420 | AUTH_NONE, |
| 12421 | OK, |
| 12422 | kServer, |
| 12423 | AUTH_ASYNC, |
| 12424 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12425 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12426 | kNoSSL, |
| 12427 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12428 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12429 | TestRound(kGet, kServerChallenge, OK), |
| 12430 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12431 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12432 | {__LINE__, |
| 12433 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12434 | AUTH_NONE, |
| 12435 | OK, |
| 12436 | kServer, |
| 12437 | AUTH_NONE, |
| 12438 | OK, |
| 12439 | 1, |
| 12440 | kNoSSL, |
| 12441 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12442 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12443 | {__LINE__, |
| 12444 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12445 | AUTH_NONE, |
| 12446 | OK, |
| 12447 | kServer, |
| 12448 | AUTH_SYNC, |
| 12449 | OK, |
| 12450 | 2, |
| 12451 | kNoSSL, |
| 12452 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12453 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12454 | {__LINE__, |
| 12455 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12456 | AUTH_NONE, |
| 12457 | OK, |
| 12458 | kServer, |
| 12459 | AUTH_SYNC, |
| 12460 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12461 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12462 | kNoSSL, |
| 12463 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12464 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12465 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12466 | {__LINE__, |
| 12467 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12468 | AUTH_NONE, |
| 12469 | OK, |
| 12470 | kServer, |
| 12471 | AUTH_ASYNC, |
| 12472 | OK, |
| 12473 | 2, |
| 12474 | kNoSSL, |
| 12475 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12476 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12477 | {__LINE__, |
| 12478 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12479 | AUTH_NONE, |
| 12480 | OK, |
| 12481 | kServer, |
| 12482 | AUTH_ASYNC, |
| 12483 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12484 | 2, |
| 12485 | kNoSSL, |
| 12486 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12487 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12488 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12489 | {__LINE__, |
| 12490 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12491 | AUTH_SYNC, |
| 12492 | OK, |
| 12493 | kServer, |
| 12494 | AUTH_NONE, |
| 12495 | OK, |
| 12496 | 2, |
| 12497 | kNoSSL, |
| 12498 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12499 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12500 | {__LINE__, |
| 12501 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12502 | AUTH_SYNC, |
| 12503 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12504 | kServer, |
| 12505 | AUTH_NONE, |
| 12506 | OK, |
| 12507 | 2, |
| 12508 | kNoSSL, |
| 12509 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12510 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12511 | {__LINE__, |
| 12512 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12513 | AUTH_ASYNC, |
| 12514 | OK, |
| 12515 | kServer, |
| 12516 | AUTH_NONE, |
| 12517 | OK, |
| 12518 | 2, |
| 12519 | kNoSSL, |
| 12520 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12521 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12522 | {__LINE__, |
| 12523 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12524 | AUTH_ASYNC, |
| 12525 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12526 | kServer, |
| 12527 | AUTH_NONE, |
| 12528 | OK, |
| 12529 | 2, |
| 12530 | kNoSSL, |
| 12531 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12532 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12533 | {__LINE__, |
| 12534 | kProxy, |
| 12535 | AUTH_ASYNC, |
| 12536 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12537 | kServer, |
| 12538 | AUTH_NONE, |
| 12539 | OK, |
| 12540 | 3, |
| 12541 | kNoSSL, |
| 12542 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12543 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12544 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12545 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12546 | {__LINE__, |
| 12547 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12548 | AUTH_SYNC, |
| 12549 | OK, |
| 12550 | kServer, |
| 12551 | AUTH_SYNC, |
| 12552 | OK, |
| 12553 | 3, |
| 12554 | kNoSSL, |
| 12555 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12556 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12557 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12558 | {__LINE__, |
| 12559 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12560 | AUTH_SYNC, |
| 12561 | OK, |
| 12562 | kServer, |
| 12563 | AUTH_SYNC, |
| 12564 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12565 | 3, |
| 12566 | kNoSSL, |
| 12567 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12568 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12569 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12570 | {__LINE__, |
| 12571 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12572 | AUTH_ASYNC, |
| 12573 | OK, |
| 12574 | kServer, |
| 12575 | AUTH_SYNC, |
| 12576 | OK, |
| 12577 | 3, |
| 12578 | kNoSSL, |
| 12579 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12580 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12581 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12582 | {__LINE__, |
| 12583 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12584 | AUTH_ASYNC, |
| 12585 | OK, |
| 12586 | kServer, |
| 12587 | AUTH_SYNC, |
| 12588 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12589 | 3, |
| 12590 | kNoSSL, |
| 12591 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12592 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12593 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12594 | {__LINE__, |
| 12595 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12596 | AUTH_SYNC, |
| 12597 | OK, |
| 12598 | kServer, |
| 12599 | AUTH_ASYNC, |
| 12600 | OK, |
| 12601 | 3, |
| 12602 | kNoSSL, |
| 12603 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12604 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12605 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12606 | {__LINE__, |
| 12607 | kProxy, |
| 12608 | AUTH_SYNC, |
| 12609 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12610 | kServer, |
| 12611 | AUTH_ASYNC, |
| 12612 | OK, |
| 12613 | 4, |
| 12614 | kNoSSL, |
| 12615 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12616 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12617 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12618 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12619 | {__LINE__, |
| 12620 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12621 | AUTH_SYNC, |
| 12622 | OK, |
| 12623 | kServer, |
| 12624 | AUTH_ASYNC, |
| 12625 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12626 | 3, |
| 12627 | kNoSSL, |
| 12628 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12629 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12630 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12631 | {__LINE__, |
| 12632 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12633 | AUTH_ASYNC, |
| 12634 | OK, |
| 12635 | kServer, |
| 12636 | AUTH_ASYNC, |
| 12637 | OK, |
| 12638 | 3, |
| 12639 | kNoSSL, |
| 12640 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12641 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12642 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12643 | {__LINE__, |
| 12644 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12645 | AUTH_ASYNC, |
| 12646 | OK, |
| 12647 | kServer, |
| 12648 | AUTH_ASYNC, |
| 12649 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12650 | 3, |
| 12651 | kNoSSL, |
| 12652 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12653 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12654 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12655 | {__LINE__, |
| 12656 | kProxy, |
| 12657 | AUTH_ASYNC, |
| 12658 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12659 | kServer, |
| 12660 | AUTH_ASYNC, |
| 12661 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12662 | 4, |
| 12663 | kNoSSL, |
| 12664 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12665 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12666 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12667 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12668 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12669 | {__LINE__, |
| 12670 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12671 | AUTH_NONE, |
| 12672 | OK, |
| 12673 | kSecureServer, |
| 12674 | AUTH_NONE, |
| 12675 | OK, |
| 12676 | 1, |
| 12677 | 0, |
| 12678 | {TestRound(kGet, kSuccess, OK)}}, |
| 12679 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12680 | {__LINE__, |
| 12681 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12682 | AUTH_NONE, |
| 12683 | OK, |
| 12684 | kSecureServer, |
| 12685 | AUTH_SYNC, |
| 12686 | OK, |
| 12687 | 2, |
| 12688 | 0, |
| 12689 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12690 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12691 | {__LINE__, |
| 12692 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12693 | AUTH_NONE, |
| 12694 | OK, |
| 12695 | kSecureServer, |
| 12696 | AUTH_SYNC, |
| 12697 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12698 | 2, |
| 12699 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12700 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12701 | {__LINE__, |
| 12702 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12703 | AUTH_NONE, |
| 12704 | OK, |
| 12705 | kSecureServer, |
| 12706 | AUTH_ASYNC, |
| 12707 | OK, |
| 12708 | 2, |
| 12709 | 0, |
| 12710 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12711 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12712 | {__LINE__, |
| 12713 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12714 | AUTH_NONE, |
| 12715 | OK, |
| 12716 | kSecureServer, |
| 12717 | AUTH_ASYNC, |
| 12718 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12719 | 2, |
| 12720 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12721 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12722 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12723 | {__LINE__, |
| 12724 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12725 | AUTH_NONE, |
| 12726 | OK, |
| 12727 | kSecureServer, |
| 12728 | AUTH_NONE, |
| 12729 | OK, |
| 12730 | 1, |
| 12731 | 0, |
| 12732 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 12733 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12734 | {__LINE__, |
| 12735 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12736 | AUTH_NONE, |
| 12737 | OK, |
| 12738 | kSecureServer, |
| 12739 | AUTH_SYNC, |
| 12740 | OK, |
| 12741 | 2, |
| 12742 | 0, |
| 12743 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12744 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12745 | {__LINE__, |
| 12746 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12747 | AUTH_NONE, |
| 12748 | OK, |
| 12749 | kSecureServer, |
| 12750 | AUTH_SYNC, |
| 12751 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12752 | 2, |
| 12753 | 0, |
| 12754 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12755 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12756 | {__LINE__, |
| 12757 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12758 | AUTH_NONE, |
| 12759 | OK, |
| 12760 | kSecureServer, |
| 12761 | AUTH_ASYNC, |
| 12762 | OK, |
| 12763 | 2, |
| 12764 | 0, |
| 12765 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12766 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12767 | {__LINE__, |
| 12768 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12769 | AUTH_NONE, |
| 12770 | OK, |
| 12771 | kSecureServer, |
| 12772 | AUTH_ASYNC, |
| 12773 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12774 | 2, |
| 12775 | 0, |
| 12776 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12777 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12778 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12779 | {__LINE__, |
| 12780 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12781 | AUTH_SYNC, |
| 12782 | OK, |
| 12783 | kSecureServer, |
| 12784 | AUTH_NONE, |
| 12785 | OK, |
| 12786 | 2, |
| 12787 | 1, |
| 12788 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12789 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12790 | {__LINE__, |
| 12791 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12792 | AUTH_SYNC, |
| 12793 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12794 | kSecureServer, |
| 12795 | AUTH_NONE, |
| 12796 | OK, |
| 12797 | 2, |
| 12798 | kNoSSL, |
| 12799 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12800 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12801 | {__LINE__, |
| 12802 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12803 | AUTH_SYNC, |
| 12804 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12805 | kSecureServer, |
| 12806 | AUTH_NONE, |
| 12807 | OK, |
| 12808 | 2, |
| 12809 | kNoSSL, |
| 12810 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12811 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12812 | {__LINE__, |
| 12813 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12814 | AUTH_SYNC, |
| 12815 | ERR_UNEXPECTED, |
| 12816 | kSecureServer, |
| 12817 | AUTH_NONE, |
| 12818 | OK, |
| 12819 | 2, |
| 12820 | kNoSSL, |
| 12821 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12822 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12823 | {__LINE__, |
| 12824 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12825 | AUTH_ASYNC, |
| 12826 | OK, |
| 12827 | kSecureServer, |
| 12828 | AUTH_NONE, |
| 12829 | OK, |
| 12830 | 2, |
| 12831 | 1, |
| 12832 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12833 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12834 | {__LINE__, |
| 12835 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12836 | AUTH_ASYNC, |
| 12837 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12838 | kSecureServer, |
| 12839 | AUTH_NONE, |
| 12840 | OK, |
| 12841 | 2, |
| 12842 | kNoSSL, |
| 12843 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12844 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12845 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12846 | {__LINE__, |
| 12847 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12848 | AUTH_SYNC, |
| 12849 | OK, |
| 12850 | kSecureServer, |
| 12851 | AUTH_SYNC, |
| 12852 | OK, |
| 12853 | 3, |
| 12854 | 1, |
| 12855 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12856 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12857 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12858 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12859 | {__LINE__, |
| 12860 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12861 | AUTH_SYNC, |
| 12862 | OK, |
| 12863 | kSecureServer, |
| 12864 | AUTH_SYNC, |
| 12865 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12866 | 3, |
| 12867 | 1, |
| 12868 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12869 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12870 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12871 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12872 | {__LINE__, |
| 12873 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12874 | AUTH_ASYNC, |
| 12875 | OK, |
| 12876 | kSecureServer, |
| 12877 | AUTH_SYNC, |
| 12878 | OK, |
| 12879 | 3, |
| 12880 | 1, |
| 12881 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12882 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12883 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12884 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12885 | {__LINE__, |
| 12886 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12887 | AUTH_ASYNC, |
| 12888 | OK, |
| 12889 | kSecureServer, |
| 12890 | AUTH_SYNC, |
| 12891 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12892 | 3, |
| 12893 | 1, |
| 12894 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12895 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12896 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12897 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12898 | {__LINE__, |
| 12899 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12900 | AUTH_SYNC, |
| 12901 | OK, |
| 12902 | kSecureServer, |
| 12903 | AUTH_ASYNC, |
| 12904 | OK, |
| 12905 | 3, |
| 12906 | 1, |
| 12907 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12908 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12909 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12910 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12911 | {__LINE__, |
| 12912 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12913 | AUTH_SYNC, |
| 12914 | OK, |
| 12915 | kSecureServer, |
| 12916 | AUTH_ASYNC, |
| 12917 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12918 | 3, |
| 12919 | 1, |
| 12920 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12921 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12922 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12923 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12924 | {__LINE__, |
| 12925 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12926 | AUTH_ASYNC, |
| 12927 | OK, |
| 12928 | kSecureServer, |
| 12929 | AUTH_ASYNC, |
| 12930 | OK, |
| 12931 | 3, |
| 12932 | 1, |
| 12933 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12934 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12935 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12936 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12937 | {__LINE__, |
| 12938 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12939 | AUTH_ASYNC, |
| 12940 | OK, |
| 12941 | kSecureServer, |
| 12942 | AUTH_ASYNC, |
| 12943 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12944 | 3, |
| 12945 | 1, |
| 12946 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12947 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12948 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12949 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12950 | {__LINE__, |
| 12951 | kProxy, |
| 12952 | AUTH_ASYNC, |
| 12953 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12954 | kSecureServer, |
| 12955 | AUTH_ASYNC, |
| 12956 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12957 | 4, |
| 12958 | 2, |
| 12959 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12960 | TestRound(kConnect, kProxyChallenge, OK), |
| 12961 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12962 | &kServerChallenge), |
| 12963 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12964 | }; |
| 12965 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12966 | for (const auto& test_config : test_configs) { |
| 12967 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12968 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12969 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12970 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12971 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12972 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12973 | |
| 12974 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12975 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12976 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12977 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12978 | std::string auth_challenge = "Mock realm=proxy"; |
| 12979 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12980 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12981 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12982 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12983 | empty_ssl_info, origin, |
| 12984 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12985 | auth_handler->SetGenerateExpectation( |
| 12986 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12987 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12988 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12989 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12990 | } |
| 12991 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12992 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12993 | std::string auth_challenge = "Mock realm=server"; |
| 12994 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12995 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12996 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12997 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12998 | empty_ssl_info, origin, |
| 12999 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13000 | auth_handler->SetGenerateExpectation( |
| 13001 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13002 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13003 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13004 | |
| 13005 | // The second handler always succeeds. It should only be used where there |
| 13006 | // are multiple auth sessions for server auth in the same network |
| 13007 | // transaction using the same auth scheme. |
| 13008 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13009 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13010 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 13011 | empty_ssl_info, origin, |
| 13012 | NetLogWithSource()); |
| 13013 | second_handler->SetGenerateExpectation(true, OK); |
| 13014 | auth_factory->AddMockHandler(second_handler.release(), |
| 13015 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13016 | } |
| 13017 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 13018 | session_deps_.proxy_resolution_service = |
| 13019 | ProxyResolutionService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13020 | } else { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 13021 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13022 | } |
| 13023 | |
| 13024 | HttpRequestInfo request; |
| 13025 | request.method = "GET"; |
| 13026 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13027 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13029 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13030 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 13031 | |
| 13032 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 13033 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13034 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13035 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13036 | const TestRound& read_write_round = test_config.rounds[round]; |
| 13037 | |
| 13038 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13039 | mock_reads.back().push_back(read_write_round.read); |
| 13040 | mock_writes.back().push_back(read_write_round.write); |
| 13041 | |
| 13042 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 13043 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 13044 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13045 | mock_reads.push_back(std::vector<MockRead>()); |
| 13046 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13047 | } |
| 13048 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13049 | if (read_write_round.extra_read) { |
| 13050 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13051 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13052 | if (read_write_round.extra_write) { |
| 13053 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 13054 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13055 | |
| 13056 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13057 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13058 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13059 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13060 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13061 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13062 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13063 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13064 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13065 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13066 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13067 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 13068 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13069 | } |
| 13070 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13071 | // Transaction must be created after DataProviders, so it's destroyed before |
| 13072 | // they are as well. |
| 13073 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13074 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13075 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13076 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13077 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13078 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13079 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13080 | int rv; |
| 13081 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13082 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13083 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13084 | rv = trans.RestartWithAuth( |
| 13085 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13086 | } |
| 13087 | if (rv == ERR_IO_PENDING) |
| 13088 | rv = callback.WaitForResult(); |
| 13089 | |
| 13090 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13091 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13092 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 13093 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13094 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 13095 | continue; |
| 13096 | } |
| 13097 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13098 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13099 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13100 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13101 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13102 | } |
| 13103 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 13104 | } |
| 13105 | } |
| 13106 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13107 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13108 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13109 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13110 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13111 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 13112 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13113 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 13114 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13115 | |
| 13116 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13117 | auth_handler->set_connection_based(true); |
| 13118 | std::string auth_challenge = "Mock realm=server"; |
| 13119 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13120 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13121 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13122 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13123 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13124 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13125 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13126 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13127 | int rv = OK; |
| 13128 | const HttpResponseInfo* response = NULL; |
| 13129 | HttpRequestInfo request; |
| 13130 | request.method = "GET"; |
| 13131 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13132 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13133 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13134 | |
| 13135 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 13136 | // to validate that the TCP socket is not released to the pool between |
| 13137 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13138 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13139 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13140 | 50, // Max sockets for pool |
| 13141 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 13142 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 13143 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13144 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 13145 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 13146 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13147 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13148 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13149 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13150 | |
| 13151 | const MockWrite kGet( |
| 13152 | "GET / HTTP/1.1\r\n" |
| 13153 | "Host: www.example.com\r\n" |
| 13154 | "Connection: keep-alive\r\n\r\n"); |
| 13155 | const MockWrite kGetAuth( |
| 13156 | "GET / HTTP/1.1\r\n" |
| 13157 | "Host: www.example.com\r\n" |
| 13158 | "Connection: keep-alive\r\n" |
| 13159 | "Authorization: auth_token\r\n\r\n"); |
| 13160 | |
| 13161 | const MockRead kServerChallenge( |
| 13162 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13163 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13164 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13165 | "Content-Length: 14\r\n\r\n" |
| 13166 | "Unauthorized\r\n"); |
| 13167 | const MockRead kSuccess( |
| 13168 | "HTTP/1.1 200 OK\r\n" |
| 13169 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13170 | "Content-Length: 3\r\n\r\n" |
| 13171 | "Yes"); |
| 13172 | |
| 13173 | MockWrite writes[] = { |
| 13174 | // First round |
| 13175 | kGet, |
| 13176 | // Second round |
| 13177 | kGetAuth, |
| 13178 | // Third round |
| 13179 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13180 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13181 | kGetAuth, |
| 13182 | // Competing request |
| 13183 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13184 | }; |
| 13185 | MockRead reads[] = { |
| 13186 | // First round |
| 13187 | kServerChallenge, |
| 13188 | // Second round |
| 13189 | kServerChallenge, |
| 13190 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13191 | kServerChallenge, |
| 13192 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13193 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13194 | // Competing response |
| 13195 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13196 | }; |
| 13197 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 13198 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13199 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13200 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13201 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13202 | |
| 13203 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13204 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13205 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13206 | if (rv == ERR_IO_PENDING) |
| 13207 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13208 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13209 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13210 | ASSERT_TRUE(response); |
| 13211 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13212 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13213 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13214 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13215 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13216 | // In between rounds, another request comes in for the same domain. |
| 13217 | // It should not be able to grab the TCP socket that trans has already |
| 13218 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13219 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13220 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13221 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 13222 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13223 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13224 | // callback_compete.WaitForResult at this point would stall forever, |
| 13225 | // since the HttpNetworkTransaction does not release the request back to |
| 13226 | // the pool until after authentication completes. |
| 13227 | |
| 13228 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13229 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13230 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13231 | if (rv == ERR_IO_PENDING) |
| 13232 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13233 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13234 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13235 | ASSERT_TRUE(response); |
| 13236 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13237 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13238 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13239 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13240 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13241 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13242 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13243 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13244 | if (rv == ERR_IO_PENDING) |
| 13245 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13246 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13247 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13248 | ASSERT_TRUE(response); |
| 13249 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13250 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13251 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13252 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13253 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13254 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13255 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13256 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13257 | if (rv == ERR_IO_PENDING) |
| 13258 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13259 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13260 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13261 | ASSERT_TRUE(response); |
| 13262 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13263 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13264 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13265 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 13266 | // auth handler should transition to a DONE state in concert with the remote |
| 13267 | // server. But that's not something we can test here with a mock handler. |
| 13268 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 13269 | auth_handler->state()); |
| 13270 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13271 | // Read the body since the fourth round was successful. This will also |
| 13272 | // release the socket back to the pool. |
| 13273 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13274 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13275 | if (rv == ERR_IO_PENDING) |
| 13276 | rv = callback.WaitForResult(); |
| 13277 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13278 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13279 | EXPECT_EQ(0, rv); |
| 13280 | // There are still 0 idle sockets, since the trans_compete transaction |
| 13281 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13282 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13283 | |
| 13284 | // The competing request can now finish. Wait for the headers and then |
| 13285 | // read the body. |
| 13286 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13287 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13288 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13289 | if (rv == ERR_IO_PENDING) |
| 13290 | rv = callback.WaitForResult(); |
| 13291 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13292 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13293 | EXPECT_EQ(0, rv); |
| 13294 | |
| 13295 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13296 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13297 | } |
| 13298 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13299 | // This tests the case that a request is issued via http instead of spdy after |
| 13300 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13301 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13302 | HttpRequestInfo request; |
| 13303 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13304 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13305 | |
| 13306 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13307 | MockWrite( |
| 13308 | "GET / HTTP/1.1\r\n" |
| 13309 | "Host: www.example.org\r\n" |
| 13310 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13311 | }; |
| 13312 | |
| 13313 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13314 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13315 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13316 | MockRead("\r\n"), |
| 13317 | MockRead("hello world"), |
| 13318 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13319 | }; |
| 13320 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13321 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13322 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13323 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13325 | |
| 13326 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13327 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13328 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13329 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13330 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13331 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13332 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13333 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13334 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13335 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13336 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13337 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13338 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13339 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13340 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13341 | ASSERT_TRUE(response); |
| 13342 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13343 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13344 | |
| 13345 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13346 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13347 | EXPECT_EQ("hello world", response_data); |
| 13348 | |
| 13349 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13350 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13351 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13352 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13353 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 13354 | // immediate server closing of the socket. |
| 13355 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13356 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13357 | HttpRequestInfo request; |
| 13358 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13359 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13360 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13361 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13362 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13364 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13365 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13366 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13367 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13368 | |
| 13369 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13370 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13371 | }; |
| 13372 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13373 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13374 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13375 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13377 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13378 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13379 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13380 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13381 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13382 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13383 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13384 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13385 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13386 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13387 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 13388 | // it gets it. This is needed since the auth handler may get destroyed |
| 13389 | // before we get a chance to query it. |
| 13390 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 13391 | public: |
| 13392 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 13393 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 13394 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13395 | |
| 13396 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13397 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 13398 | const HttpRequestInfo* request, |
| 13399 | const CompletionCallback& callback, |
| 13400 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13401 | *url_ = request->url; |
| 13402 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 13403 | credentials, request, callback, auth_token); |
| 13404 | } |
| 13405 | |
| 13406 | private: |
| 13407 | GURL* url_; |
| 13408 | }; |
| 13409 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13410 | // Test that if we cancel the transaction as the connection is completing, that |
| 13411 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13412 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13413 | // Setup everything about the connection to complete synchronously, so that |
| 13414 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13415 | // for is the callback from the HttpStreamRequest. |
| 13416 | // Then cancel the transaction. |
| 13417 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13418 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13419 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13420 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13421 | MockRead(SYNCHRONOUS, "hello world"), |
| 13422 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13423 | }; |
| 13424 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13425 | HttpRequestInfo request; |
| 13426 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13427 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13428 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13429 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13431 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13432 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13433 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13434 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13435 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13436 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13438 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13439 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13440 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13441 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13442 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13443 | trans.reset(); // Cancel the transaction here. |
| 13444 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13445 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13446 | } |
| 13447 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13448 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13449 | // stream is drained properly and added back to the socket pool. The main |
| 13450 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13451 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13452 | // deleted. |
| 13453 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13454 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13455 | MockRead data_reads[] = { |
| 13456 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13457 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13458 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13459 | MockRead(ASYNC, "1"), |
| 13460 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13461 | // HttpNetworkTransaction has been deleted. |
| 13462 | MockRead(ASYNC, "2"), |
| 13463 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13464 | }; |
| 13465 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13466 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13467 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13468 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13469 | |
| 13470 | { |
| 13471 | HttpRequestInfo request; |
| 13472 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13473 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13474 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13475 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13476 | TestCompletionCallback callback; |
| 13477 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13478 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13480 | callback.WaitForResult(); |
| 13481 | |
| 13482 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13483 | ASSERT_TRUE(response); |
| 13484 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13485 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13486 | |
| 13487 | // The transaction and HttpRequestInfo are deleted. |
| 13488 | } |
| 13489 | |
| 13490 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13491 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13492 | |
| 13493 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13494 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13495 | } |
| 13496 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13497 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13498 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 13499 | session_deps_.proxy_resolution_service = |
| 13500 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13501 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13502 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13503 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13504 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13505 | HttpRequestInfo request; |
| 13506 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13507 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13508 | |
| 13509 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13510 | MockWrite( |
| 13511 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13512 | "Host: www.example.org\r\n" |
| 13513 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13514 | }; |
| 13515 | |
| 13516 | MockRead data_reads1[] = { |
| 13517 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13518 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13519 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13520 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13521 | }; |
| 13522 | |
| 13523 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13524 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13525 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13526 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13527 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13528 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13529 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13530 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13531 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13532 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13533 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13534 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13535 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13536 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13537 | |
| 13538 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13539 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13541 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13542 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13543 | |
| 13544 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13545 | EXPECT_EQ(200, response->headers->response_code()); |
| 13546 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13547 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13548 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13549 | HostPortPair::FromString("myproxy:70")), |
| 13550 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13551 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13552 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13553 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13554 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13555 | |
| 13556 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13557 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13558 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13559 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13560 | } |
| 13561 | |
| 13562 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13563 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 13564 | session_deps_.proxy_resolution_service = |
| 13565 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13566 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13567 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13569 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13570 | HttpRequestInfo request; |
| 13571 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13572 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13573 | |
| 13574 | // Since we have proxy, should try to establish tunnel. |
| 13575 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13576 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13577 | "Host: www.example.org:443\r\n" |
| 13578 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13579 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13580 | MockWrite("GET / HTTP/1.1\r\n" |
| 13581 | "Host: www.example.org\r\n" |
| 13582 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13583 | }; |
| 13584 | |
| 13585 | MockRead data_reads1[] = { |
| 13586 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13587 | |
| 13588 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13589 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13590 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13591 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13592 | }; |
| 13593 | |
| 13594 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13595 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13596 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13597 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13598 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13599 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13600 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13602 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13603 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13604 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13605 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13606 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13607 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13608 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13609 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13610 | |
| 13611 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13612 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13613 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13614 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13615 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13616 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13617 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13618 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13619 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13620 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13621 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13622 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13623 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13624 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13625 | |
| 13626 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13627 | EXPECT_EQ(200, response->headers->response_code()); |
| 13628 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13629 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13630 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13631 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13632 | HostPortPair::FromString("myproxy:70")), |
| 13633 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13634 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13635 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13636 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13637 | |
| 13638 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13639 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13640 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13641 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13642 | } |
| 13643 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13644 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13645 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13646 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 13647 | session_deps_.proxy_resolution_service = |
| 13648 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13649 | BoundTestNetLog log; |
| 13650 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13651 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13652 | |
| 13653 | HttpRequestInfo request; |
| 13654 | request.method = "GET"; |
| 13655 | request.url = GURL("https://[::1]:443/"); |
| 13656 | |
| 13657 | // Since we have proxy, should try to establish tunnel. |
| 13658 | MockWrite data_writes1[] = { |
| 13659 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13660 | "Host: [::1]:443\r\n" |
| 13661 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13662 | |
| 13663 | MockWrite("GET / HTTP/1.1\r\n" |
| 13664 | "Host: [::1]\r\n" |
| 13665 | "Connection: keep-alive\r\n\r\n"), |
| 13666 | }; |
| 13667 | |
| 13668 | MockRead data_reads1[] = { |
| 13669 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13670 | |
| 13671 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13672 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13673 | MockRead("Content-Length: 100\r\n\r\n"), |
| 13674 | MockRead(SYNCHRONOUS, OK), |
| 13675 | }; |
| 13676 | |
| 13677 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13678 | data_writes1, arraysize(data_writes1)); |
| 13679 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13680 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13681 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13682 | |
| 13683 | TestCompletionCallback callback1; |
| 13684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13685 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13686 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13687 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13688 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13689 | |
| 13690 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13691 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13692 | TestNetLogEntry::List entries; |
| 13693 | log.GetEntries(&entries); |
| 13694 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13695 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13696 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13697 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13698 | entries, pos, |
| 13699 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13700 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13701 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13702 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13703 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13704 | |
| 13705 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13706 | EXPECT_EQ(200, response->headers->response_code()); |
| 13707 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13708 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13709 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13710 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13711 | HostPortPair::FromString("myproxy:70")), |
| 13712 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13713 | |
| 13714 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13715 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13716 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13717 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13718 | } |
| 13719 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13720 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 13721 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13722 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 13723 | session_deps_.proxy_resolution_service = |
| 13724 | ProxyResolutionService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13725 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13726 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13728 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13729 | HttpRequestInfo request; |
| 13730 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13731 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13732 | |
| 13733 | // Since we have proxy, should try to establish tunnel. |
| 13734 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13735 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13736 | "Host: www.example.org:443\r\n" |
| 13737 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13738 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13739 | MockWrite("GET / HTTP/1.1\r\n" |
| 13740 | "Host: www.example.org\r\n" |
| 13741 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13742 | }; |
| 13743 | |
| 13744 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13745 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13746 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13747 | }; |
| 13748 | |
| 13749 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13750 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13751 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13752 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13753 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13754 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13755 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13756 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13757 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13758 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13759 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13760 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13761 | |
| 13762 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13763 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13764 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13765 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13766 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13767 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13768 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13769 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13770 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13771 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13772 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13773 | } |
| 13774 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13775 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13776 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13777 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13778 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13779 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13780 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13781 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13782 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13783 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13784 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13785 | }; |
| 13786 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13787 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13788 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13789 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13790 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13791 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13792 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13793 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13794 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13795 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13796 | |
| 13797 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13798 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13799 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 13800 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13801 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13802 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13803 | |
| 13804 | HttpRequestInfo request; |
| 13805 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13806 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13807 | |
| 13808 | // This is the important line that marks this as a preconnect. |
| 13809 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13810 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13811 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13812 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13813 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13814 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13816 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13817 | } |
| 13818 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13819 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13820 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13821 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13822 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13823 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13824 | request_info.url = GURL("https://www.example.com/"); |
| 13825 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13826 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13827 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13828 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13829 | MockWrite data_writes[] = { |
| 13830 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13831 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13832 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13833 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13834 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13835 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13836 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13837 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13839 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13840 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13841 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13842 | rv = callback.WaitForResult(); |
| 13843 | ASSERT_EQ(error, rv); |
| 13844 | } |
| 13845 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13846 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13847 | // Just check a grab bag of cert errors. |
| 13848 | static const int kErrors[] = { |
| 13849 | ERR_CERT_COMMON_NAME_INVALID, |
| 13850 | ERR_CERT_AUTHORITY_INVALID, |
| 13851 | ERR_CERT_DATE_INVALID, |
| 13852 | }; |
| 13853 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13854 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13855 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13856 | } |
| 13857 | } |
| 13858 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13859 | // Ensure that a client certificate is removed from the SSL client auth |
| 13860 | // cache when: |
| 13861 | // 1) No proxy is involved. |
| 13862 | // 2) TLS False Start is disabled. |
| 13863 | // 3) The initial TLS handshake requests a client certificate. |
| 13864 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13865 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13866 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13867 | request_info.url = GURL("https://www.example.com/"); |
| 13868 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13869 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13870 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13871 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13872 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13873 | |
| 13874 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13875 | // CertificateRequest is received for the first time, the handshake will |
| 13876 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13877 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13878 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13879 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13880 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13881 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13882 | |
| 13883 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13884 | // False Start is not being used, the result of the SSL handshake will be |
| 13885 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13886 | // matches the result of a server sending a handshake_failure alert, |
| 13887 | // rather than a Finished message, because it requires a client |
| 13888 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13889 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13890 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13891 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13892 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13893 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13894 | |
| 13895 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13896 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13897 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13898 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13899 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13900 | // requiring a client certificate, this fallback handshake should also |
| 13901 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13902 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13903 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13904 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13905 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13906 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13907 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13908 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13909 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13910 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13911 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13912 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13913 | // requiring a client certificate, this fallback handshake should also |
| 13914 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13915 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13916 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13917 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13918 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13919 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13920 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13921 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13922 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13923 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13924 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13925 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13926 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13927 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13928 | |
| 13929 | // Complete the SSL handshake, which should abort due to requiring a |
| 13930 | // client certificate. |
| 13931 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13932 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13933 | |
| 13934 | // Indicate that no certificate should be supplied. From the perspective |
| 13935 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13936 | // certificate, so this is the same as supply a |
| 13937 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13938 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13939 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13940 | |
| 13941 | // Ensure the certificate was added to the client auth cache before |
| 13942 | // allowing the connection to continue restarting. |
| 13943 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13944 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13945 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13946 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13947 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13948 | |
| 13949 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13950 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13951 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13952 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13953 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13954 | |
| 13955 | // Ensure that the client certificate is removed from the cache on a |
| 13956 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13957 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13958 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13959 | } |
| 13960 | |
| 13961 | // Ensure that a client certificate is removed from the SSL client auth |
| 13962 | // cache when: |
| 13963 | // 1) No proxy is involved. |
| 13964 | // 2) TLS False Start is enabled. |
| 13965 | // 3) The initial TLS handshake requests a client certificate. |
| 13966 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13967 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13968 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13969 | request_info.url = GURL("https://www.example.com/"); |
| 13970 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13971 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13972 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13973 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13974 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13975 | |
| 13976 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13977 | // return successfully after reading up to the peer's Certificate message. |
| 13978 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13979 | // enqueue application data to be sent in the same packet as the |
| 13980 | // ChangeCipherSpec and Finished messages. |
| 13981 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13982 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13983 | // Finished messages. If there was an error negotiating with the peer, |
| 13984 | // such as due to the peer requiring a client certificate when none was |
| 13985 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13986 | // called. |
| 13987 | |
| 13988 | // Like the non-False Start case, when a client certificate is requested by |
| 13989 | // the peer, the handshake is aborted during the Connect() call. |
| 13990 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13991 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13992 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13993 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13994 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13995 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13996 | |
| 13997 | // When a client certificate is supplied, Connect() will not be aborted |
| 13998 | // when the peer requests the certificate. Instead, the handshake will |
| 13999 | // artificially succeed, allowing the caller to write the HTTP request to |
| 14000 | // the socket. The handshake messages are not processed until Read() is |
| 14001 | // called, which then detects that the handshake was aborted, due to the |
| 14002 | // peer sending a handshake_failure because it requires a client |
| 14003 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14004 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14005 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14006 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14007 | MockRead data2_reads[] = { |
| 14008 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14009 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14010 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14011 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14012 | |
| 14013 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14014 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 14015 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14016 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14017 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14018 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14019 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14020 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14021 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14022 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 14023 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14024 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14025 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14026 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14027 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14028 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14029 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14030 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14031 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14032 | ssl_data5.cert_request_info = cert_request.get(); |
| 14033 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14034 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14035 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 14036 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14037 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14038 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14039 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14040 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14041 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14042 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14043 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14044 | |
| 14045 | // Complete the SSL handshake, which should abort due to requiring a |
| 14046 | // client certificate. |
| 14047 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14048 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14049 | |
| 14050 | // Indicate that no certificate should be supplied. From the perspective |
| 14051 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14052 | // certificate, so this is the same as supply a |
| 14053 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14054 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14055 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14056 | |
| 14057 | // Ensure the certificate was added to the client auth cache before |
| 14058 | // allowing the connection to continue restarting. |
| 14059 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14060 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14061 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14062 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14063 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14064 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14065 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14066 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14067 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14068 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14069 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14070 | |
| 14071 | // Ensure that the client certificate is removed from the cache on a |
| 14072 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14073 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14074 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14075 | } |
| 14076 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14077 | // Ensure that a client certificate is removed from the SSL client auth |
| 14078 | // cache when: |
| 14079 | // 1) An HTTPS proxy is involved. |
| 14080 | // 3) The HTTPS proxy requests a client certificate. |
| 14081 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 14082 | // proxy. |
| 14083 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 14084 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14085 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 14086 | session_deps_.proxy_resolution_service = |
| 14087 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14088 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14089 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14090 | |
| 14091 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14092 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14093 | |
| 14094 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 14095 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 14096 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 14097 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14098 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14099 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14100 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14101 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14102 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14103 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14104 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14105 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14106 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14107 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14108 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14109 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14110 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 14111 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14112 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14113 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14115 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14116 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14117 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14118 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14119 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14120 | requests[0].url = GURL("https://www.example.com/"); |
| 14121 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14122 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14123 | |
| 14124 | requests[1].url = GURL("http://www.example.com/"); |
| 14125 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14126 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14127 | |
| 14128 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14129 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14130 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14131 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14132 | |
| 14133 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14134 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14135 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14136 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14137 | |
| 14138 | // Complete the SSL handshake, which should abort due to requiring a |
| 14139 | // client certificate. |
| 14140 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14141 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14142 | |
| 14143 | // Indicate that no certificate should be supplied. From the perspective |
| 14144 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14145 | // certificate, so this is the same as supply a |
| 14146 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14147 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14148 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14149 | |
| 14150 | // Ensure the certificate was added to the client auth cache before |
| 14151 | // allowing the connection to continue restarting. |
| 14152 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14153 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14154 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14155 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14156 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14157 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 14158 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14159 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14160 | HostPortPair("www.example.com", 443), &client_cert, |
| 14161 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14162 | |
| 14163 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 14164 | // then consume ssl_data3, which should also fail. The result code is |
| 14165 | // checked against what ssl_data3 should return. |
| 14166 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14167 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14168 | |
| 14169 | // Now that the new handshake has failed, ensure that the client |
| 14170 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14171 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14172 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14173 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14174 | HostPortPair("www.example.com", 443), &client_cert, |
| 14175 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14176 | } |
| 14177 | } |
| 14178 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14179 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14180 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14181 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14182 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14183 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14184 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14185 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14186 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14187 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14188 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14189 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14190 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14191 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14192 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14193 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14194 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14195 | SpdySerializedFrame host1_resp_body( |
| 14196 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14197 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14198 | SpdySerializedFrame host2_resp_body( |
| 14199 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14200 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14201 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14202 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14203 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14204 | }; |
| 14205 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14206 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14207 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14208 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14209 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14210 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14211 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14212 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14213 | HttpRequestInfo request1; |
| 14214 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14215 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14216 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14217 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14218 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14219 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14220 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14221 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14222 | |
| 14223 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14224 | ASSERT_TRUE(response); |
| 14225 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14226 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14227 | |
| 14228 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14229 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14230 | EXPECT_EQ("hello!", response_data); |
| 14231 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14232 | // Preload mail.example.com into HostCache. |
| 14233 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 14234 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14235 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14236 | std::unique_ptr<HostResolver::Request> request; |
| 14237 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14238 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14239 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14240 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14241 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14242 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14243 | |
| 14244 | HttpRequestInfo request2; |
| 14245 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14246 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14247 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14248 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14249 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14250 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14251 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14252 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14253 | |
| 14254 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14255 | ASSERT_TRUE(response); |
| 14256 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14257 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14258 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14259 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14260 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14261 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14262 | } |
| 14263 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14264 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14265 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14266 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14267 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14268 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14269 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14270 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14271 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14272 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14273 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14274 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14275 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14276 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14277 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14278 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14279 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14280 | SpdySerializedFrame host1_resp_body( |
| 14281 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14282 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14283 | SpdySerializedFrame host2_resp_body( |
| 14284 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14285 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14286 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14287 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14288 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14289 | }; |
| 14290 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14291 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14292 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14293 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14294 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14295 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14296 | |
| 14297 | TestCompletionCallback callback; |
| 14298 | HttpRequestInfo request1; |
| 14299 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14300 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14301 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14302 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14303 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14304 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14305 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14306 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14307 | |
| 14308 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14309 | ASSERT_TRUE(response); |
| 14310 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14311 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14312 | |
| 14313 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14314 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14315 | EXPECT_EQ("hello!", response_data); |
| 14316 | |
| 14317 | HttpRequestInfo request2; |
| 14318 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14319 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14320 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14321 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14322 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14323 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14324 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14325 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14326 | |
| 14327 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14328 | ASSERT_TRUE(response); |
| 14329 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14330 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14331 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14332 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14333 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14334 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14335 | } |
| 14336 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14337 | // Regression test for https://crbug.com/546991. |
| 14338 | // The server might not be able to serve an IP pooled request, and might send a |
| 14339 | // 421 Misdirected Request response status to indicate this. |
| 14340 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 14341 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 14342 | // Two hosts resolve to the same IP address. |
| 14343 | const std::string ip_addr = "1.2.3.4"; |
| 14344 | IPAddress ip; |
| 14345 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14346 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14347 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14348 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14349 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14350 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14351 | |
| 14352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14353 | |
| 14354 | // Two requests on the first connection. |
| 14355 | SpdySerializedFrame req1( |
| 14356 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14357 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14358 | SpdySerializedFrame req2( |
| 14359 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14360 | SpdySerializedFrame rst( |
| 14361 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14362 | MockWrite writes1[] = { |
| 14363 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14364 | CreateMockWrite(rst, 6), |
| 14365 | }; |
| 14366 | |
| 14367 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14368 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14369 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14370 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14371 | response_headers[kHttp2StatusHeader] = "421"; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14372 | SpdySerializedFrame resp2( |
| 14373 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 14374 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14375 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14376 | |
| 14377 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14378 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14379 | arraysize(writes1)); |
| 14380 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14381 | |
| 14382 | AddSSLSocketData(); |
| 14383 | |
| 14384 | // Retry the second request on a second connection. |
| 14385 | SpdyTestUtil spdy_util2; |
| 14386 | SpdySerializedFrame req3( |
| 14387 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14388 | MockWrite writes2[] = { |
| 14389 | CreateMockWrite(req3, 0), |
| 14390 | }; |
| 14391 | |
| 14392 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14393 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14394 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14395 | MockRead(ASYNC, 0, 3)}; |
| 14396 | |
| 14397 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14398 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14399 | arraysize(writes2)); |
| 14400 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14401 | |
| 14402 | AddSSLSocketData(); |
| 14403 | |
| 14404 | // Preload mail.example.org into HostCache. |
| 14405 | HostPortPair host_port("mail.example.org", 443); |
| 14406 | HostResolver::RequestInfo resolve_info(host_port); |
| 14407 | AddressList ignored; |
| 14408 | std::unique_ptr<HostResolver::Request> request; |
| 14409 | TestCompletionCallback callback; |
| 14410 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14411 | &ignored, callback.callback(), |
| 14412 | &request, NetLogWithSource()); |
| 14413 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14414 | rv = callback.WaitForResult(); |
| 14415 | EXPECT_THAT(rv, IsOk()); |
| 14416 | |
| 14417 | HttpRequestInfo request1; |
| 14418 | request1.method = "GET"; |
| 14419 | request1.url = GURL("https://www.example.org/"); |
| 14420 | request1.load_flags = 0; |
| 14421 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14422 | |
| 14423 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14424 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14425 | rv = callback.WaitForResult(); |
| 14426 | EXPECT_THAT(rv, IsOk()); |
| 14427 | |
| 14428 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14429 | ASSERT_TRUE(response); |
| 14430 | ASSERT_TRUE(response->headers); |
| 14431 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14432 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14433 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14434 | std::string response_data; |
| 14435 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14436 | EXPECT_EQ("hello!", response_data); |
| 14437 | |
| 14438 | HttpRequestInfo request2; |
| 14439 | request2.method = "GET"; |
| 14440 | request2.url = GURL("https://mail.example.org/"); |
| 14441 | request2.load_flags = 0; |
| 14442 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14443 | |
| 14444 | BoundTestNetLog log; |
| 14445 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14446 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14447 | rv = callback.WaitForResult(); |
| 14448 | EXPECT_THAT(rv, IsOk()); |
| 14449 | |
| 14450 | response = trans2.GetResponseInfo(); |
| 14451 | ASSERT_TRUE(response); |
| 14452 | ASSERT_TRUE(response->headers); |
| 14453 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14454 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14455 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14456 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14457 | EXPECT_EQ("hello!", response_data); |
| 14458 | |
| 14459 | TestNetLogEntry::List entries; |
| 14460 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14461 | ExpectLogContainsSomewhere( |
| 14462 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14463 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14464 | } |
| 14465 | |
| 14466 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14467 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14468 | // portions of the response. |
| 14469 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14470 | // Two hosts resolve to the same IP address. |
| 14471 | const std::string ip_addr = "1.2.3.4"; |
| 14472 | IPAddress ip; |
| 14473 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14474 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14475 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14476 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14477 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14478 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14479 | |
| 14480 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14481 | |
| 14482 | // Two requests on the first connection. |
| 14483 | SpdySerializedFrame req1( |
| 14484 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14485 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14486 | SpdySerializedFrame req2( |
| 14487 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14488 | SpdySerializedFrame rst( |
| 14489 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14490 | MockWrite writes1[] = { |
| 14491 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14492 | CreateMockWrite(rst, 6), |
| 14493 | }; |
| 14494 | |
| 14495 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14496 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14497 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14498 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14499 | response_headers[kHttp2StatusHeader] = "421"; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14500 | SpdySerializedFrame resp2( |
| 14501 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14502 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14503 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14504 | |
| 14505 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14506 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14507 | arraysize(writes1)); |
| 14508 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14509 | |
| 14510 | AddSSLSocketData(); |
| 14511 | |
| 14512 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14513 | // Retry again. |
| 14514 | SpdyTestUtil spdy_util2; |
| 14515 | SpdySerializedFrame req3( |
| 14516 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14517 | MockWrite writes2[] = { |
| 14518 | CreateMockWrite(req3, 0), |
| 14519 | }; |
| 14520 | |
| 14521 | SpdySerializedFrame resp3( |
| 14522 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 14523 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14524 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14525 | MockRead(ASYNC, 0, 3)}; |
| 14526 | |
| 14527 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14528 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14529 | arraysize(writes2)); |
| 14530 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14531 | |
| 14532 | AddSSLSocketData(); |
| 14533 | |
| 14534 | // Preload mail.example.org into HostCache. |
| 14535 | HostPortPair host_port("mail.example.org", 443); |
| 14536 | HostResolver::RequestInfo resolve_info(host_port); |
| 14537 | AddressList ignored; |
| 14538 | std::unique_ptr<HostResolver::Request> request; |
| 14539 | TestCompletionCallback callback; |
| 14540 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14541 | &ignored, callback.callback(), |
| 14542 | &request, NetLogWithSource()); |
| 14543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14544 | rv = callback.WaitForResult(); |
| 14545 | EXPECT_THAT(rv, IsOk()); |
| 14546 | |
| 14547 | HttpRequestInfo request1; |
| 14548 | request1.method = "GET"; |
| 14549 | request1.url = GURL("https://www.example.org/"); |
| 14550 | request1.load_flags = 0; |
| 14551 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14552 | |
| 14553 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14554 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14555 | rv = callback.WaitForResult(); |
| 14556 | EXPECT_THAT(rv, IsOk()); |
| 14557 | |
| 14558 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14559 | ASSERT_TRUE(response); |
| 14560 | ASSERT_TRUE(response->headers); |
| 14561 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14562 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14563 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14564 | std::string response_data; |
| 14565 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14566 | EXPECT_EQ("hello!", response_data); |
| 14567 | |
| 14568 | HttpRequestInfo request2; |
| 14569 | request2.method = "GET"; |
| 14570 | request2.url = GURL("https://mail.example.org/"); |
| 14571 | request2.load_flags = 0; |
| 14572 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14573 | |
| 14574 | BoundTestNetLog log; |
| 14575 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14576 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14577 | rv = callback.WaitForResult(); |
| 14578 | EXPECT_THAT(rv, IsOk()); |
| 14579 | |
| 14580 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14581 | // caller. |
| 14582 | response = trans2.GetResponseInfo(); |
| 14583 | ASSERT_TRUE(response); |
| 14584 | ASSERT_TRUE(response->headers); |
| 14585 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14586 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14587 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14588 | EXPECT_TRUE(response->ssl_info.cert); |
| 14589 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14590 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14591 | } |
| 14592 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14593 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14594 | public: |
| 14595 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14596 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14597 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14598 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14599 | int ResolveFromCache(const RequestInfo& info, |
| 14600 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14601 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14602 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14603 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14604 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14605 | return rv; |
| 14606 | } |
| 14607 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14608 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14609 | const HostPortPair host_port_; |
| 14610 | }; |
| 14611 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14612 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14613 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14614 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14615 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14616 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14617 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14618 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14619 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14620 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14621 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14622 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14623 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14624 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14625 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14626 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14627 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14628 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14629 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14630 | SpdySerializedFrame host1_resp_body( |
| 14631 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14632 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14633 | SpdySerializedFrame host2_resp_body( |
| 14634 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14635 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14636 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14637 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14638 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14639 | }; |
| 14640 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14641 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14642 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14643 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14644 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14645 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14646 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14647 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14648 | HttpRequestInfo request1; |
| 14649 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14650 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14651 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14652 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14653 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14654 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14655 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14656 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14657 | |
| 14658 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14659 | ASSERT_TRUE(response); |
| 14660 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14661 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14662 | |
| 14663 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14664 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14665 | EXPECT_EQ("hello!", response_data); |
| 14666 | |
| 14667 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14668 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14669 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14670 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14671 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14672 | &ignored, callback.callback(), |
| 14673 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14674 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14675 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14676 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14677 | |
| 14678 | HttpRequestInfo request2; |
| 14679 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14680 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14681 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14682 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14683 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14684 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14685 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14686 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14687 | |
| 14688 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14689 | ASSERT_TRUE(response); |
| 14690 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14691 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14692 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14693 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14694 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14695 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14696 | } |
| 14697 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14698 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14699 | const std::string https_url = "https://www.example.org:8080/"; |
| 14700 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14701 | |
| 14702 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14703 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14704 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14705 | |
| 14706 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14707 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14708 | }; |
| 14709 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14710 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14711 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14712 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14713 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14714 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14715 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14716 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14717 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14718 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14719 | |
| 14720 | // HTTP GET for the HTTP URL |
| 14721 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14722 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14723 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14724 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14725 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14726 | }; |
| 14727 | |
| 14728 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14729 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 14730 | MockRead(ASYNC, 2, "hello"), |
| 14731 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14732 | }; |
| 14733 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14734 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14735 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14736 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14737 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14738 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14739 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14740 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14741 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14742 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14743 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14744 | |
| 14745 | // Start the first transaction to set up the SpdySession |
| 14746 | HttpRequestInfo request1; |
| 14747 | request1.method = "GET"; |
| 14748 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14749 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14750 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14751 | TestCompletionCallback callback1; |
| 14752 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14753 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14754 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14755 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14756 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14757 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14758 | |
| 14759 | // Now, start the HTTP request |
| 14760 | HttpRequestInfo request2; |
| 14761 | request2.method = "GET"; |
| 14762 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14763 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14764 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14765 | TestCompletionCallback callback2; |
| 14766 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14767 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14768 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14769 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14770 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14771 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14772 | } |
| 14773 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14774 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 14775 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14776 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14777 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14778 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14779 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14780 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14781 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14782 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14783 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14784 | |
| 14785 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14786 | // negotiated. |
| 14787 | StaticSocketDataProvider data; |
| 14788 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14789 | |
| 14790 | // 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] | 14791 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14792 | // mocked. This way the request relies on the alternate Job. |
| 14793 | StaticSocketDataProvider data_refused; |
| 14794 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14795 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14796 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14797 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14798 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14799 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14800 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14801 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14802 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14803 | http_server_properties->SetHttp2AlternativeService( |
| 14804 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14805 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14806 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14807 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14808 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14809 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14810 | TestCompletionCallback callback; |
| 14811 | |
| 14812 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14813 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14814 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14815 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14816 | } |
| 14817 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14818 | // 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] | 14819 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14820 | // succeeds, the request should succeed, even if the latter fails because |
| 14821 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14822 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14823 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14824 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14825 | |
| 14826 | // Negotiate HTTP/1.1 with alternative. |
| 14827 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14828 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14829 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 14830 | |
| 14831 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14832 | // negotiated. |
| 14833 | StaticSocketDataProvider data; |
| 14834 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14835 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14836 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14837 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14838 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14839 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 14840 | |
| 14841 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14842 | MockWrite("GET / HTTP/1.1\r\n" |
| 14843 | "Host: www.example.org\r\n" |
| 14844 | "Connection: keep-alive\r\n\r\n"), |
| 14845 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14846 | "Host: www.example.org\r\n" |
| 14847 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14848 | }; |
| 14849 | |
| 14850 | MockRead http_reads[] = { |
| 14851 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14852 | MockRead("Content-Type: text/html\r\n"), |
| 14853 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14854 | MockRead("foobar"), |
| 14855 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14856 | MockRead("Content-Type: text/html\r\n"), |
| 14857 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14858 | MockRead("another"), |
| 14859 | }; |
| 14860 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14861 | http_writes, arraysize(http_writes)); |
| 14862 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14863 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14864 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14865 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14866 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14867 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14868 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14869 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14870 | http_server_properties->SetHttp2AlternativeService( |
| 14871 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14872 | |
| 14873 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14874 | HttpRequestInfo request1; |
| 14875 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14876 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14877 | request1.load_flags = 0; |
| 14878 | TestCompletionCallback callback1; |
| 14879 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14880 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14881 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14882 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14883 | |
| 14884 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14885 | ASSERT_TRUE(response1); |
| 14886 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14887 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14888 | |
| 14889 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14890 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14891 | EXPECT_EQ("foobar", response_data1); |
| 14892 | |
| 14893 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14894 | // for alternative service. |
| 14895 | EXPECT_TRUE( |
| 14896 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14897 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14898 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14899 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14900 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14901 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14902 | HttpRequestInfo request2; |
| 14903 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14904 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14905 | request2.load_flags = 0; |
| 14906 | TestCompletionCallback callback2; |
| 14907 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14908 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14909 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14910 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14911 | |
| 14912 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14913 | ASSERT_TRUE(response2); |
| 14914 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14915 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14916 | |
| 14917 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14918 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14919 | EXPECT_EQ("another", response_data2); |
| 14920 | } |
| 14921 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14922 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14923 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14924 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14925 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14926 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14927 | HostPortPair alternative("alternative.example.org", 443); |
| 14928 | std::string origin_url = "https://origin.example.org:443"; |
| 14929 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14930 | |
| 14931 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14932 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14933 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14934 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14935 | |
| 14936 | // HTTP/1.1 data for |request1| and |request2|. |
| 14937 | MockWrite http_writes[] = { |
| 14938 | MockWrite( |
| 14939 | "GET / HTTP/1.1\r\n" |
| 14940 | "Host: alternative.example.org\r\n" |
| 14941 | "Connection: keep-alive\r\n\r\n"), |
| 14942 | MockWrite( |
| 14943 | "GET / HTTP/1.1\r\n" |
| 14944 | "Host: alternative.example.org\r\n" |
| 14945 | "Connection: keep-alive\r\n\r\n"), |
| 14946 | }; |
| 14947 | |
| 14948 | MockRead http_reads[] = { |
| 14949 | MockRead( |
| 14950 | "HTTP/1.1 200 OK\r\n" |
| 14951 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14952 | "Content-Length: 40\r\n\r\n" |
| 14953 | "first HTTP/1.1 response from alternative"), |
| 14954 | MockRead( |
| 14955 | "HTTP/1.1 200 OK\r\n" |
| 14956 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14957 | "Content-Length: 41\r\n\r\n" |
| 14958 | "second HTTP/1.1 response from alternative"), |
| 14959 | }; |
| 14960 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14961 | http_writes, arraysize(http_writes)); |
| 14962 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14963 | |
| 14964 | // This test documents that an alternate Job should not pool to an already |
| 14965 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14966 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14967 | StaticSocketDataProvider data_refused; |
| 14968 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14969 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14970 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14971 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14972 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14973 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14974 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14975 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14976 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14977 | http_server_properties->SetHttp2AlternativeService( |
| 14978 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14979 | |
| 14980 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14981 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14982 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14983 | request1.method = "GET"; |
| 14984 | request1.url = GURL(alternative_url); |
| 14985 | request1.load_flags = 0; |
| 14986 | TestCompletionCallback callback1; |
| 14987 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14988 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14989 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14990 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14991 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14992 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14993 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14994 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14995 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14996 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14997 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14998 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14999 | |
| 15000 | // Request for origin.example.org, which has an alternative service. This |
| 15001 | // will start two Jobs: the alternative looks for connections to pool to, |
| 15002 | // 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] | 15003 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15004 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15005 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15006 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15007 | request2.method = "GET"; |
| 15008 | request2.url = GURL(origin_url); |
| 15009 | request2.load_flags = 0; |
| 15010 | TestCompletionCallback callback2; |
| 15011 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15012 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15013 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15014 | |
| 15015 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 15016 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15017 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15018 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15019 | request3.method = "GET"; |
| 15020 | request3.url = GURL(alternative_url); |
| 15021 | request3.load_flags = 0; |
| 15022 | TestCompletionCallback callback3; |
| 15023 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15024 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15025 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15026 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15027 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15028 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15029 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15030 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15031 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 15032 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15033 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15034 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 15035 | } |
| 15036 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15037 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15038 | const std::string https_url = "https://www.example.org:8080/"; |
| 15039 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15040 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15041 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15042 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15043 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15044 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15045 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15046 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15047 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15048 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15049 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15050 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15051 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 15052 | |
| 15053 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 15054 | SpdyHeaderBlock req2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 15055 | req2_block[kHttp2MethodHeader] = "GET"; |
| 15056 | req2_block[kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 15057 | req2_block[kHttp2SchemeHeader] = "http"; |
| 15058 | req2_block[kHttp2PathHeader] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15059 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15060 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15061 | |
| 15062 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15063 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 15064 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15065 | }; |
| 15066 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15067 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15068 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15069 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15070 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15071 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 15072 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15073 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15074 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15075 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15076 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15077 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15078 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15079 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15080 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15081 | CreateMockRead(wrapped_resp1, 4), |
| 15082 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15083 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15084 | CreateMockRead(resp2, 8), |
| 15085 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15086 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 15087 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15088 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15089 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15090 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15091 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15092 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15093 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 15094 | session_deps_.proxy_resolution_service = |
| 15095 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15096 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15097 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15098 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15099 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15100 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15101 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15102 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15103 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15104 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15105 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15106 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15107 | |
| 15108 | // Start the first transaction to set up the SpdySession |
| 15109 | HttpRequestInfo request1; |
| 15110 | request1.method = "GET"; |
| 15111 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15112 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15113 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15114 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15115 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15116 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15117 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15118 | data1.RunUntilPaused(); |
| 15119 | base::RunLoop().RunUntilIdle(); |
| 15120 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15121 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15122 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15123 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15124 | LoadTimingInfo load_timing_info1; |
| 15125 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 15126 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 15127 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15128 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15129 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15130 | HttpRequestInfo request2; |
| 15131 | request2.method = "GET"; |
| 15132 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15133 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15134 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15135 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15136 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15137 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15138 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15139 | data1.RunUntilPaused(); |
| 15140 | base::RunLoop().RunUntilIdle(); |
| 15141 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15142 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15143 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15144 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15145 | |
| 15146 | LoadTimingInfo load_timing_info2; |
| 15147 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 15148 | // The established SPDY sessions is considered reused by the HTTP request. |
| 15149 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 15150 | // HTTP requests over a SPDY session should have a different connection |
| 15151 | // socket_log_id than requests over a tunnel. |
| 15152 | 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] | 15153 | } |
| 15154 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15155 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 15156 | // that we do not pool other origins that resolve to the same IP when |
| 15157 | // the certificate does not match the new origin. |
| 15158 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15159 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15160 | const std::string url1 = "http://www.example.org/"; |
| 15161 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15162 | const std::string ip_addr = "1.2.3.4"; |
| 15163 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15164 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15165 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15166 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15167 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 15168 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15169 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15170 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15171 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15172 | |
| 15173 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15174 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15175 | }; |
| 15176 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15177 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15178 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15179 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15180 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 15181 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15182 | }; |
| 15183 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15184 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15185 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 15186 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 15187 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15188 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15189 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15190 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15191 | |
| 15192 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15193 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15194 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15195 | |
| 15196 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15197 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15198 | }; |
| 15199 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15200 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15201 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 15202 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15203 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15204 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15205 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15206 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15207 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15208 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15209 | |
| 15210 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 15211 | // all others direct. |
| 15212 | ProxyConfig proxy_config; |
| 15213 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 15214 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15215 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15216 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15217 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15218 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15219 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15220 | // Load a valid cert. Note, that this does not need to |
| 15221 | // be valid for proxy because the MockSSLClientSocket does |
| 15222 | // not actually verify it. But SpdySession will use this |
| 15223 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 15224 | ssl1.ssl_info.cert = |
| 15225 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 15226 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15227 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15228 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15229 | |
| 15230 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15231 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15232 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15233 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15234 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15235 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15236 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15237 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15238 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15239 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15240 | |
| 15241 | // Start the first transaction to set up the SpdySession |
| 15242 | HttpRequestInfo request1; |
| 15243 | request1.method = "GET"; |
| 15244 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15245 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15246 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15247 | TestCompletionCallback callback1; |
| 15248 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15249 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15250 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15251 | data1.RunUntilPaused(); |
| 15252 | base::RunLoop().RunUntilIdle(); |
| 15253 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15254 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15255 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15256 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15257 | |
| 15258 | // Now, start the HTTP request |
| 15259 | HttpRequestInfo request2; |
| 15260 | request2.method = "GET"; |
| 15261 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15262 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15263 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15264 | TestCompletionCallback callback2; |
| 15265 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15266 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15267 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15268 | |
| 15269 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15270 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15271 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15272 | } |
| 15273 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15274 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 15275 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 15276 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 15277 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15278 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15279 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15280 | |
| 15281 | MockRead reads1[] = { |
| 15282 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 15283 | }; |
| 15284 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15285 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15286 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15287 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15288 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15289 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15290 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15291 | }; |
| 15292 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15293 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15294 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15295 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15296 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 15297 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15298 | }; |
| 15299 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15300 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15301 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15302 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15303 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15304 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15305 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15306 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15307 | |
| 15308 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15309 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15310 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15311 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15312 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15313 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15314 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15315 | |
| 15316 | // Start the first transaction to set up the SpdySession and verify that |
| 15317 | // connection was closed. |
| 15318 | HttpRequestInfo request1; |
| 15319 | request1.method = "GET"; |
| 15320 | request1.url = GURL(https_url); |
| 15321 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15322 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15323 | TestCompletionCallback callback1; |
| 15324 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15325 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15326 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15327 | |
| 15328 | // Now, start the second request and make sure it succeeds. |
| 15329 | HttpRequestInfo request2; |
| 15330 | request2.method = "GET"; |
| 15331 | request2.url = GURL(https_url); |
| 15332 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15333 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15334 | TestCompletionCallback callback2; |
| 15335 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15336 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15337 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15338 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15339 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15340 | } |
| 15341 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15342 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15343 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15344 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15345 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15346 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15347 | |
| 15348 | // Use two different hosts with different IPs so they don't get pooled. |
| 15349 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 15350 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15351 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15352 | |
| 15353 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15354 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15355 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15356 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15357 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15358 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15359 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15360 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15361 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15362 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15363 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15364 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15365 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15366 | SpdySerializedFrame host1_resp_body( |
| 15367 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15368 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15369 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15370 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15371 | }; |
| 15372 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15373 | // Use a separate test instance for the separate SpdySession that will be |
| 15374 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15375 | SpdyTestUtil spdy_util_2; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15376 | auto spdy1_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15377 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 15378 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15379 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 15380 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15381 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15382 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15383 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15384 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15385 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15386 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15387 | SpdySerializedFrame host2_resp_body( |
| 15388 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15389 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15390 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15391 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15392 | }; |
| 15393 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15394 | auto spdy2_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15395 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 15396 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15397 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 15398 | |
| 15399 | MockWrite http_write[] = { |
| 15400 | MockWrite("GET / HTTP/1.1\r\n" |
| 15401 | "Host: www.a.com\r\n" |
| 15402 | "Connection: keep-alive\r\n\r\n"), |
| 15403 | }; |
| 15404 | |
| 15405 | MockRead http_read[] = { |
| 15406 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15407 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15408 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15409 | MockRead("hello!"), |
| 15410 | }; |
| 15411 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 15412 | http_write, arraysize(http_write)); |
| 15413 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15414 | |
| 15415 | HostPortPair host_port_pair_a("www.a.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15416 | SpdySessionKey spdy_session_key_a(host_port_pair_a, ProxyServer::Direct(), |
| 15417 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15418 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15419 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15420 | |
| 15421 | TestCompletionCallback callback; |
| 15422 | HttpRequestInfo request1; |
| 15423 | request1.method = "GET"; |
| 15424 | request1.url = GURL("https://www.a.com/"); |
| 15425 | request1.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15426 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15427 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15428 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15429 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15431 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15432 | |
| 15433 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15434 | ASSERT_TRUE(response); |
| 15435 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15436 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15437 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15438 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15439 | |
| 15440 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15441 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15442 | EXPECT_EQ("hello!", response_data); |
| 15443 | trans.reset(); |
| 15444 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15445 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15446 | |
| 15447 | HostPortPair host_port_pair_b("www.b.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15448 | SpdySessionKey spdy_session_key_b(host_port_pair_b, ProxyServer::Direct(), |
| 15449 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15450 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15451 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15452 | HttpRequestInfo request2; |
| 15453 | request2.method = "GET"; |
| 15454 | request2.url = GURL("https://www.b.com/"); |
| 15455 | request2.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15456 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15457 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15458 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15459 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15460 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15461 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15462 | |
| 15463 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15464 | ASSERT_TRUE(response); |
| 15465 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15466 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15467 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15468 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15469 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15470 | EXPECT_EQ("hello!", response_data); |
| 15471 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15472 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15473 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15474 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15475 | |
| 15476 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15477 | SpdySessionKey spdy_session_key_a1(host_port_pair_a1, ProxyServer::Direct(), |
| 15478 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15479 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15480 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15481 | HttpRequestInfo request3; |
| 15482 | request3.method = "GET"; |
| 15483 | request3.url = GURL("http://www.a.com/"); |
| 15484 | request3.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15485 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15486 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15487 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15488 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15490 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15491 | |
| 15492 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15493 | ASSERT_TRUE(response); |
| 15494 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15495 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15496 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15497 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15498 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15499 | EXPECT_EQ("hello!", response_data); |
| 15500 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15501 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15502 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15503 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15504 | } |
| 15505 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15506 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15507 | HttpRequestInfo request; |
| 15508 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15509 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15510 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15511 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15512 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15513 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15514 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15515 | StaticSocketDataProvider data; |
| 15516 | data.set_connect_data(mock_connect); |
| 15517 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15518 | |
| 15519 | TestCompletionCallback callback; |
| 15520 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15521 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15522 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15523 | |
| 15524 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15525 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15526 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15527 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15528 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15529 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15530 | |
| 15531 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15532 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15533 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15534 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15535 | |
| 15536 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15537 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15538 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15539 | } |
| 15540 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15541 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15542 | HttpRequestInfo request; |
| 15543 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15544 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15545 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15546 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15547 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15548 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15549 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15550 | StaticSocketDataProvider data; |
| 15551 | data.set_connect_data(mock_connect); |
| 15552 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15553 | |
| 15554 | TestCompletionCallback callback; |
| 15555 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15556 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15557 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15558 | |
| 15559 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15560 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15561 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15562 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15563 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15564 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15565 | |
| 15566 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15567 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15568 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15569 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15570 | |
| 15571 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15572 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15573 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15574 | } |
| 15575 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15576 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15577 | HttpRequestInfo request; |
| 15578 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15579 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15580 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15581 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15582 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15583 | |
| 15584 | MockWrite data_writes[] = { |
| 15585 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15586 | }; |
| 15587 | MockRead data_reads[] = { |
| 15588 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15589 | }; |
| 15590 | |
| 15591 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15592 | data_writes, arraysize(data_writes)); |
| 15593 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15594 | |
| 15595 | TestCompletionCallback callback; |
| 15596 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15597 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15598 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15599 | |
| 15600 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15601 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15602 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15603 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15604 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15605 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15606 | } |
| 15607 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15608 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15609 | HttpRequestInfo request; |
| 15610 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15611 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15612 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15613 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15614 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15615 | |
| 15616 | MockWrite data_writes[] = { |
| 15617 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 15618 | }; |
| 15619 | MockRead data_reads[] = { |
| 15620 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15621 | }; |
| 15622 | |
| 15623 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15624 | data_writes, arraysize(data_writes)); |
| 15625 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15626 | |
| 15627 | TestCompletionCallback callback; |
| 15628 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15629 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15630 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15631 | |
| 15632 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15633 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15634 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15635 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15636 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15637 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15638 | } |
| 15639 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15640 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15641 | HttpRequestInfo request; |
| 15642 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15643 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15644 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15645 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15646 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15647 | |
| 15648 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15649 | MockWrite( |
| 15650 | "GET / HTTP/1.1\r\n" |
| 15651 | "Host: www.example.org\r\n" |
| 15652 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15653 | }; |
| 15654 | MockRead data_reads[] = { |
| 15655 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15656 | }; |
| 15657 | |
| 15658 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15659 | data_writes, arraysize(data_writes)); |
| 15660 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15661 | |
| 15662 | TestCompletionCallback callback; |
| 15663 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15664 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15666 | |
| 15667 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15668 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15669 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15670 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15671 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15672 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15673 | } |
| 15674 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15675 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15676 | HttpRequestInfo request; |
| 15677 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15678 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15679 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15680 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15681 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15682 | |
| 15683 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15684 | MockWrite( |
| 15685 | "GET / HTTP/1.1\r\n" |
| 15686 | "Host: www.example.org\r\n" |
| 15687 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15688 | }; |
| 15689 | MockRead data_reads[] = { |
| 15690 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 15691 | }; |
| 15692 | |
| 15693 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15694 | data_writes, arraysize(data_writes)); |
| 15695 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15696 | |
| 15697 | TestCompletionCallback callback; |
| 15698 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15699 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15700 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15701 | |
| 15702 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15703 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15704 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15705 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15706 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15707 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15708 | } |
| 15709 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15710 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15711 | HttpRequestInfo request; |
| 15712 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15713 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15714 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 15715 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15716 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15717 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15718 | |
| 15719 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15720 | MockWrite( |
| 15721 | "GET / HTTP/1.1\r\n" |
| 15722 | "Host: www.example.org\r\n" |
| 15723 | "Connection: keep-alive\r\n" |
| 15724 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15725 | }; |
| 15726 | MockRead data_reads[] = { |
| 15727 | MockRead("HTTP/1.1 200 OK\r\n" |
| 15728 | "Content-Length: 5\r\n\r\n" |
| 15729 | "hello"), |
| 15730 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 15731 | }; |
| 15732 | |
| 15733 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15734 | data_writes, arraysize(data_writes)); |
| 15735 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15736 | |
| 15737 | TestCompletionCallback callback; |
| 15738 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15739 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15741 | |
| 15742 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15743 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15744 | |
| 15745 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15746 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15747 | std::string foo; |
| 15748 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 15749 | EXPECT_EQ("bar", foo); |
| 15750 | } |
| 15751 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15752 | namespace { |
| 15753 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15754 | // Fake HttpStream that simply records calls to SetPriority(). |
| 15755 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15756 | public base::SupportsWeakPtr<FakeStream> { |
| 15757 | public: |
| 15758 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15759 | ~FakeStream() override = default; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15760 | |
| 15761 | RequestPriority priority() const { return priority_; } |
| 15762 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15763 | int InitializeStream(const HttpRequestInfo* request_info, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 15764 | bool can_send_early, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15765 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15766 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15767 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15768 | return ERR_IO_PENDING; |
| 15769 | } |
| 15770 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15771 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15772 | HttpResponseInfo* response, |
| 15773 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15774 | ADD_FAILURE(); |
| 15775 | return ERR_UNEXPECTED; |
| 15776 | } |
| 15777 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15778 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15779 | ADD_FAILURE(); |
| 15780 | return ERR_UNEXPECTED; |
| 15781 | } |
| 15782 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15783 | int ReadResponseBody(IOBuffer* buf, |
| 15784 | int buf_len, |
| 15785 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15786 | ADD_FAILURE(); |
| 15787 | return ERR_UNEXPECTED; |
| 15788 | } |
| 15789 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15790 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15791 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15792 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15793 | ADD_FAILURE(); |
| 15794 | return false; |
| 15795 | } |
| 15796 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15797 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15798 | ADD_FAILURE(); |
| 15799 | return false; |
| 15800 | } |
| 15801 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15802 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15803 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15804 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15805 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15806 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 15807 | ADD_FAILURE(); |
| 15808 | return 0; |
| 15809 | } |
| 15810 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15811 | int64_t GetTotalSentBytes() const override { |
| 15812 | ADD_FAILURE(); |
| 15813 | return 0; |
| 15814 | } |
| 15815 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15816 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15817 | ADD_FAILURE(); |
| 15818 | return false; |
| 15819 | } |
| 15820 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15821 | bool GetAlternativeService( |
| 15822 | AlternativeService* alternative_service) const override { |
| 15823 | ADD_FAILURE(); |
| 15824 | return false; |
| 15825 | } |
| 15826 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15827 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 15828 | |
| 15829 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15830 | ADD_FAILURE(); |
| 15831 | } |
| 15832 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15833 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15834 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15835 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15836 | TokenBindingType tb_type, |
| 15837 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15838 | ADD_FAILURE(); |
| 15839 | return ERR_NOT_IMPLEMENTED; |
| 15840 | } |
| 15841 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15842 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15843 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15844 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15845 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15846 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15847 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15848 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15849 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 15850 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 15851 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15852 | private: |
| 15853 | RequestPriority priority_; |
| 15854 | |
| 15855 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15856 | }; |
| 15857 | |
| 15858 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15859 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15860 | class FakeStreamRequest : public HttpStreamRequest, |
| 15861 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15862 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15863 | FakeStreamRequest(RequestPriority priority, |
| 15864 | HttpStreamRequest::Delegate* delegate) |
| 15865 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15866 | delegate_(delegate), |
| 15867 | websocket_stream_create_helper_(NULL) {} |
| 15868 | |
| 15869 | FakeStreamRequest(RequestPriority priority, |
| 15870 | HttpStreamRequest::Delegate* delegate, |
| 15871 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15872 | : priority_(priority), |
| 15873 | delegate_(delegate), |
| 15874 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15875 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15876 | ~FakeStreamRequest() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15877 | |
| 15878 | RequestPriority priority() const { return priority_; } |
| 15879 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15880 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15881 | websocket_stream_create_helper() const { |
| 15882 | return websocket_stream_create_helper_; |
| 15883 | } |
| 15884 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15885 | // Create a new FakeStream and pass it to the request's |
| 15886 | // delegate. Returns a weak pointer to the FakeStream. |
| 15887 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15888 | auto fake_stream = std::make_unique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15889 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15890 | // immediately delete |fake_stream|. |
| 15891 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 15892 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15893 | return weak_stream; |
| 15894 | } |
| 15895 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15896 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15897 | ADD_FAILURE(); |
| 15898 | return ERR_UNEXPECTED; |
| 15899 | } |
| 15900 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15901 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15902 | ADD_FAILURE(); |
| 15903 | return LoadState(); |
| 15904 | } |
| 15905 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15906 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15907 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15908 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15909 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15910 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15911 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15912 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15913 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15914 | const ConnectionAttempts& connection_attempts() const override { |
| 15915 | static ConnectionAttempts no_attempts; |
| 15916 | return no_attempts; |
| 15917 | } |
| 15918 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15919 | private: |
| 15920 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15921 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15922 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15923 | |
| 15924 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15925 | }; |
| 15926 | |
| 15927 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15928 | class FakeStreamFactory : public HttpStreamFactory { |
| 15929 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15930 | FakeStreamFactory() = default; |
| 15931 | ~FakeStreamFactory() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15932 | |
| 15933 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15934 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15935 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15936 | return last_stream_request_; |
| 15937 | } |
| 15938 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15939 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 15940 | const HttpRequestInfo& info, |
| 15941 | RequestPriority priority, |
| 15942 | const SSLConfig& server_ssl_config, |
| 15943 | const SSLConfig& proxy_ssl_config, |
| 15944 | HttpStreamRequest::Delegate* delegate, |
| 15945 | bool enable_ip_based_pooling, |
| 15946 | bool enable_alternative_services, |
| 15947 | const NetLogWithSource& net_log) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15948 | auto fake_request = std::make_unique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15949 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15950 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15951 | } |
| 15952 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15953 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15954 | const HttpRequestInfo& info, |
| 15955 | RequestPriority priority, |
| 15956 | const SSLConfig& server_ssl_config, |
| 15957 | const SSLConfig& proxy_ssl_config, |
| 15958 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15959 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15960 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15961 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15962 | NOTREACHED(); |
| 15963 | return nullptr; |
| 15964 | } |
| 15965 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15966 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15967 | const HttpRequestInfo& info, |
| 15968 | RequestPriority priority, |
| 15969 | const SSLConfig& server_ssl_config, |
| 15970 | const SSLConfig& proxy_ssl_config, |
| 15971 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15972 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15973 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15974 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15975 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15976 | auto fake_request = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15977 | std::make_unique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15978 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15979 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15980 | } |
| 15981 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15982 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15983 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15984 | ADD_FAILURE(); |
| 15985 | } |
| 15986 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15987 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15988 | ADD_FAILURE(); |
| 15989 | return NULL; |
| 15990 | } |
| 15991 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15992 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15993 | const std::string& parent_absolute_name) const override { |
| 15994 | ADD_FAILURE(); |
| 15995 | } |
| 15996 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15997 | private: |
| 15998 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15999 | |
| 16000 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 16001 | }; |
| 16002 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16003 | // TODO(ricea): Maybe unify this with the one in |
| 16004 | // url_request_http_job_unittest.cc ? |
| 16005 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 16006 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16007 | FakeWebSocketBasicHandshakeStream( |
| 16008 | std::unique_ptr<ClientSocketHandle> connection, |
| 16009 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 16010 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16011 | |
| 16012 | // Fake implementation of HttpStreamBase methods. |
| 16013 | // This ends up being quite "real" because this object has to really send data |
| 16014 | // on the mock socket. It might be easier to use the real implementation, but |
| 16015 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 16016 | // difficult. |
| 16017 | int InitializeStream(const HttpRequestInfo* request_info, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 16018 | bool can_send_early, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16019 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16020 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16021 | const CompletionCallback& callback) override { |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 16022 | state_.Initialize(request_info, can_send_early, priority, net_log, |
| 16023 | callback); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16024 | return OK; |
| 16025 | } |
| 16026 | |
| 16027 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 16028 | HttpResponseInfo* response, |
| 16029 | const CompletionCallback& callback) override { |
| 16030 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 16031 | TRAFFIC_ANNOTATION_FOR_TESTS, response, |
| 16032 | callback); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16033 | } |
| 16034 | |
| 16035 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 16036 | return parser()->ReadResponseHeaders(callback); |
| 16037 | } |
| 16038 | |
| 16039 | int ReadResponseBody(IOBuffer* buf, |
| 16040 | int buf_len, |
| 16041 | const CompletionCallback& callback) override { |
| 16042 | NOTREACHED(); |
| 16043 | return ERR_IO_PENDING; |
| 16044 | } |
| 16045 | |
| 16046 | void Close(bool not_reusable) override { |
| 16047 | if (parser()) |
| 16048 | parser()->Close(true); |
| 16049 | } |
| 16050 | |
| 16051 | bool IsResponseBodyComplete() const override { |
| 16052 | NOTREACHED(); |
| 16053 | return false; |
| 16054 | } |
| 16055 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16056 | bool IsConnectionReused() const override { |
| 16057 | NOTREACHED(); |
| 16058 | return false; |
| 16059 | } |
| 16060 | void SetConnectionReused() override { NOTREACHED(); } |
| 16061 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 16062 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16063 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 16064 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16065 | NOTREACHED(); |
| 16066 | return 0; |
| 16067 | } |
| 16068 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 16069 | int64_t GetTotalSentBytes() const override { |
| 16070 | NOTREACHED(); |
| 16071 | return 0; |
| 16072 | } |
| 16073 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16074 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 16075 | NOTREACHED(); |
| 16076 | return false; |
| 16077 | } |
| 16078 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 16079 | bool GetAlternativeService( |
| 16080 | AlternativeService* alternative_service) const override { |
| 16081 | ADD_FAILURE(); |
| 16082 | return false; |
| 16083 | } |
| 16084 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 16085 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16086 | |
| 16087 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 16088 | NOTREACHED(); |
| 16089 | } |
| 16090 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16091 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 16092 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 16093 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 16094 | TokenBindingType tb_type, |
| 16095 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16096 | ADD_FAILURE(); |
| 16097 | return ERR_NOT_IMPLEMENTED; |
| 16098 | } |
| 16099 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16100 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 16101 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 16102 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 16103 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16104 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 16105 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16106 | HttpStream* RenewStreamForAuth() override { |
| 16107 | NOTREACHED(); |
| 16108 | return nullptr; |
| 16109 | } |
| 16110 | |
| 16111 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16112 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16113 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16114 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16115 | } |
| 16116 | |
| 16117 | private: |
| 16118 | HttpStreamParser* parser() const { return state_.parser(); } |
| 16119 | HttpBasicState state_; |
| 16120 | |
| 16121 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 16122 | }; |
| 16123 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16124 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 16125 | // worth doing. |
| 16126 | class FakeWebSocketStreamCreateHelper : |
| 16127 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 16128 | public: |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 16129 | std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16130 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 16131 | bool using_proxy) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16132 | return std::make_unique<FakeWebSocketBasicHandshakeStream>( |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 16133 | std::move(connection), using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16134 | } |
| 16135 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16136 | ~FakeWebSocketStreamCreateHelper() override = default; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16137 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16138 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16139 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16140 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16141 | } |
| 16142 | }; |
| 16143 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16144 | } // namespace |
| 16145 | |
| 16146 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 16147 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16148 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16149 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16150 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16151 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16152 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16153 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16154 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16155 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16156 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16157 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16158 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16159 | TestCompletionCallback callback; |
| 16160 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16161 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16162 | |
| 16163 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16164 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16165 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16166 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16167 | } |
| 16168 | |
| 16169 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16170 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16171 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16173 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16174 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16175 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16176 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16177 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16178 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16179 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16180 | TestCompletionCallback callback; |
| 16181 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16182 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16183 | |
| 16184 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16185 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16186 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16187 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16188 | |
| 16189 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16190 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16191 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 16192 | } |
| 16193 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16194 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16195 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16196 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16197 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16198 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16199 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16200 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16201 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16202 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16203 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16204 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16205 | TestCompletionCallback callback; |
| 16206 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16207 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16208 | |
| 16209 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16210 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16211 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16212 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16213 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16214 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 16215 | |
| 16216 | trans.SetPriority(LOWEST); |
| 16217 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 16218 | } |
| 16219 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16220 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16221 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 16222 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 16223 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16224 | std::string test_cases[] = {"ws://www.example.org/", |
| 16225 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16226 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16227 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16228 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16229 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 16230 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
Bence Béky | 8cae04e | 2018-01-15 18:37:06 | [diff] [blame] | 16231 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16232 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16233 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16234 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16235 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 16236 | &websocket_stream_create_helper); |
| 16237 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16238 | TestCompletionCallback callback; |
| 16239 | request.method = "GET"; |
| 16240 | request.url = GURL(test_cases[i]); |
| 16241 | |
| 16242 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16243 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16244 | |
| 16245 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16246 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16247 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16248 | EXPECT_EQ(&websocket_stream_create_helper, |
| 16249 | fake_request->websocket_stream_create_helper()); |
| 16250 | } |
| 16251 | } |
| 16252 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16253 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16254 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16255 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16256 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16257 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16258 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16259 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16260 | |
| 16261 | // Set up SSL request. |
| 16262 | |
| 16263 | HttpRequestInfo ssl_request; |
| 16264 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16265 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16266 | |
| 16267 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16268 | MockWrite( |
| 16269 | "GET / HTTP/1.1\r\n" |
| 16270 | "Host: www.example.org\r\n" |
| 16271 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16272 | }; |
| 16273 | MockRead ssl_reads[] = { |
| 16274 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16275 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16276 | MockRead("hello world"), |
| 16277 | MockRead(SYNCHRONOUS, OK), |
| 16278 | }; |
| 16279 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 16280 | ssl_writes, arraysize(ssl_writes)); |
| 16281 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16282 | |
| 16283 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16284 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16285 | |
| 16286 | // Set up HTTP request. |
| 16287 | |
| 16288 | HttpRequestInfo http_request; |
| 16289 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16290 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16291 | |
| 16292 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16293 | MockWrite( |
| 16294 | "GET / HTTP/1.1\r\n" |
| 16295 | "Host: www.example.org\r\n" |
| 16296 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16297 | }; |
| 16298 | MockRead http_reads[] = { |
| 16299 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16300 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16301 | MockRead("falafel"), |
| 16302 | MockRead(SYNCHRONOUS, OK), |
| 16303 | }; |
| 16304 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16305 | http_writes, arraysize(http_writes)); |
| 16306 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16307 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16308 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16309 | |
| 16310 | // Start the SSL request. |
| 16311 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16312 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16313 | ASSERT_EQ(ERR_IO_PENDING, |
| 16314 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 16315 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16316 | |
| 16317 | // Start the HTTP request. Pool should stall. |
| 16318 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16319 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16320 | ASSERT_EQ(ERR_IO_PENDING, |
| 16321 | http_trans.Start(&http_request, http_callback.callback(), |
| 16322 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16323 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16324 | |
| 16325 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16326 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16327 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16328 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16329 | EXPECT_EQ("hello world", response_data); |
| 16330 | |
| 16331 | // The SSL socket should automatically be closed, so the HTTP request can |
| 16332 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16333 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 16334 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16335 | |
| 16336 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16337 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16338 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16339 | EXPECT_EQ("falafel", response_data); |
| 16340 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16341 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16342 | } |
| 16343 | |
| 16344 | // Tests that when a SSL connection is established but there's no corresponding |
| 16345 | // request that needs it, the new socket is closed if the transport socket pool |
| 16346 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16347 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16348 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16349 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16350 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16351 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16352 | |
| 16353 | // Set up an ssl request. |
| 16354 | |
| 16355 | HttpRequestInfo ssl_request; |
| 16356 | ssl_request.method = "GET"; |
| 16357 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 16358 | |
| 16359 | // No data will be sent on the SSL socket. |
| 16360 | StaticSocketDataProvider ssl_data; |
| 16361 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16362 | |
| 16363 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16365 | |
| 16366 | // Set up HTTP request. |
| 16367 | |
| 16368 | HttpRequestInfo http_request; |
| 16369 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16370 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16371 | |
| 16372 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16373 | MockWrite( |
| 16374 | "GET / HTTP/1.1\r\n" |
| 16375 | "Host: www.example.org\r\n" |
| 16376 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16377 | }; |
| 16378 | MockRead http_reads[] = { |
| 16379 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16380 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16381 | MockRead("falafel"), |
| 16382 | MockRead(SYNCHRONOUS, OK), |
| 16383 | }; |
| 16384 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16385 | http_writes, arraysize(http_writes)); |
| 16386 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16387 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16388 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16389 | |
| 16390 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 16391 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16392 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16393 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16394 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16395 | |
| 16396 | // Start the HTTP request. Pool should stall. |
| 16397 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16398 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16399 | ASSERT_EQ(ERR_IO_PENDING, |
| 16400 | http_trans.Start(&http_request, http_callback.callback(), |
| 16401 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16402 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16403 | |
| 16404 | // The SSL connection will automatically be closed once the connection is |
| 16405 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16406 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16407 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16408 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16409 | EXPECT_EQ("falafel", response_data); |
| 16410 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16411 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16412 | } |
| 16413 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16414 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16415 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16416 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16417 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16418 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16419 | |
| 16420 | HttpRequestInfo request; |
| 16421 | request.method = "POST"; |
| 16422 | request.url = GURL("http://www.foo.com/"); |
| 16423 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16424 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16425 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16426 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16427 | // Send headers successfully, but get an error while sending the body. |
| 16428 | MockWrite data_writes[] = { |
| 16429 | MockWrite("POST / HTTP/1.1\r\n" |
| 16430 | "Host: www.foo.com\r\n" |
| 16431 | "Connection: keep-alive\r\n" |
| 16432 | "Content-Length: 3\r\n\r\n"), |
| 16433 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16434 | }; |
| 16435 | |
| 16436 | MockRead data_reads[] = { |
| 16437 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16438 | MockRead("hello world"), |
| 16439 | MockRead(SYNCHRONOUS, OK), |
| 16440 | }; |
| 16441 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16442 | arraysize(data_writes)); |
| 16443 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16444 | |
| 16445 | TestCompletionCallback callback; |
| 16446 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16447 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16448 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16449 | |
| 16450 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16451 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16452 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16453 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16454 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16455 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16456 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16457 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16458 | |
| 16459 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16460 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16461 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16462 | EXPECT_EQ("hello world", response_data); |
| 16463 | } |
| 16464 | |
| 16465 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16466 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16467 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16468 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16469 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16470 | MockWrite data_writes[] = { |
| 16471 | MockWrite("GET / HTTP/1.1\r\n" |
| 16472 | "Host: www.foo.com\r\n" |
| 16473 | "Connection: keep-alive\r\n\r\n"), |
| 16474 | MockWrite("POST / HTTP/1.1\r\n" |
| 16475 | "Host: www.foo.com\r\n" |
| 16476 | "Connection: keep-alive\r\n" |
| 16477 | "Content-Length: 3\r\n\r\n"), |
| 16478 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16479 | }; |
| 16480 | |
| 16481 | MockRead data_reads[] = { |
| 16482 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16483 | "Content-Length: 14\r\n\r\n"), |
| 16484 | MockRead("first response"), |
| 16485 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16486 | "Content-Length: 15\r\n\r\n"), |
| 16487 | MockRead("second response"), |
| 16488 | MockRead(SYNCHRONOUS, OK), |
| 16489 | }; |
| 16490 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16491 | arraysize(data_writes)); |
| 16492 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16493 | |
| 16494 | TestCompletionCallback callback; |
| 16495 | HttpRequestInfo request1; |
| 16496 | request1.method = "GET"; |
| 16497 | request1.url = GURL("http://www.foo.com/"); |
| 16498 | request1.load_flags = 0; |
| 16499 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16500 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16501 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16502 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16503 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16504 | |
| 16505 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16506 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16507 | |
| 16508 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16509 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16510 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16511 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16512 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16513 | |
| 16514 | std::string response_data1; |
| 16515 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16516 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16517 | EXPECT_EQ("first response", response_data1); |
| 16518 | // Delete the transaction to release the socket back into the socket pool. |
| 16519 | trans1.reset(); |
| 16520 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16521 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16522 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16523 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16524 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16525 | |
| 16526 | HttpRequestInfo request2; |
| 16527 | request2.method = "POST"; |
| 16528 | request2.url = GURL("http://www.foo.com/"); |
| 16529 | request2.upload_data_stream = &upload_data_stream; |
| 16530 | request2.load_flags = 0; |
| 16531 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16532 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16533 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16534 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16535 | |
| 16536 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16537 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16538 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16539 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16540 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16541 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16542 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16543 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16544 | |
| 16545 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16546 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16547 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16548 | EXPECT_EQ("second response", response_data2); |
| 16549 | } |
| 16550 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16551 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16552 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16553 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16554 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16555 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16556 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16557 | |
| 16558 | HttpRequestInfo request; |
| 16559 | request.method = "POST"; |
| 16560 | request.url = GURL("http://www.foo.com/"); |
| 16561 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16562 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16563 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16564 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16565 | // Send headers successfully, but get an error while sending the body. |
| 16566 | MockWrite data_writes[] = { |
| 16567 | MockWrite("POST / HTTP/1.1\r\n" |
| 16568 | "Host: www.foo.com\r\n" |
| 16569 | "Connection: keep-alive\r\n" |
| 16570 | "Content-Length: 3\r\n\r\n" |
| 16571 | "fo"), |
| 16572 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16573 | }; |
| 16574 | |
| 16575 | MockRead data_reads[] = { |
| 16576 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16577 | MockRead("hello world"), |
| 16578 | MockRead(SYNCHRONOUS, OK), |
| 16579 | }; |
| 16580 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16581 | arraysize(data_writes)); |
| 16582 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16583 | |
| 16584 | TestCompletionCallback callback; |
| 16585 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16586 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16587 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16588 | |
| 16589 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16590 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16591 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16592 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16593 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16594 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16595 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16596 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16597 | |
| 16598 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16599 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16600 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16601 | EXPECT_EQ("hello world", response_data); |
| 16602 | } |
| 16603 | |
| 16604 | // This tests the more common case than the previous test, where headers and |
| 16605 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16606 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16607 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16608 | |
| 16609 | HttpRequestInfo request; |
| 16610 | request.method = "POST"; |
| 16611 | request.url = GURL("http://www.foo.com/"); |
| 16612 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16613 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16614 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16615 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16616 | // Send headers successfully, but get an error while sending the body. |
| 16617 | MockWrite data_writes[] = { |
| 16618 | MockWrite("POST / HTTP/1.1\r\n" |
| 16619 | "Host: www.foo.com\r\n" |
| 16620 | "Connection: keep-alive\r\n" |
| 16621 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16622 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16623 | }; |
| 16624 | |
| 16625 | MockRead data_reads[] = { |
| 16626 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16627 | MockRead("hello world"), |
| 16628 | MockRead(SYNCHRONOUS, OK), |
| 16629 | }; |
| 16630 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16631 | arraysize(data_writes)); |
| 16632 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16633 | |
| 16634 | TestCompletionCallback callback; |
| 16635 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16636 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16638 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16639 | // they can't be merged with the body in a single send. Not currently |
| 16640 | // necessary since a chunked body is never merged with headers, but this makes |
| 16641 | // the test more future proof. |
| 16642 | base::RunLoop().RunUntilIdle(); |
| 16643 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16644 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16645 | |
| 16646 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16647 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16648 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16649 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16650 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16651 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16652 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16653 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16654 | |
| 16655 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16656 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16657 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16658 | EXPECT_EQ("hello world", response_data); |
| 16659 | } |
| 16660 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16661 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16662 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16663 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16664 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16665 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16666 | |
| 16667 | HttpRequestInfo request; |
| 16668 | request.method = "POST"; |
| 16669 | request.url = GURL("http://www.foo.com/"); |
| 16670 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16671 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16672 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16673 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16674 | |
| 16675 | MockWrite data_writes[] = { |
| 16676 | MockWrite("POST / HTTP/1.1\r\n" |
| 16677 | "Host: www.foo.com\r\n" |
| 16678 | "Connection: keep-alive\r\n" |
| 16679 | "Content-Length: 3\r\n\r\n"), |
| 16680 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16681 | }; |
| 16682 | |
| 16683 | MockRead data_reads[] = { |
| 16684 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16685 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16686 | MockRead("hello world"), |
| 16687 | MockRead(SYNCHRONOUS, OK), |
| 16688 | }; |
| 16689 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16690 | arraysize(data_writes)); |
| 16691 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16692 | |
| 16693 | TestCompletionCallback callback; |
| 16694 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16695 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16697 | |
| 16698 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16699 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16700 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16701 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16702 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16703 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16704 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16705 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16706 | |
| 16707 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16708 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16709 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16710 | EXPECT_EQ("hello world", response_data); |
| 16711 | } |
| 16712 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16713 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16714 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16715 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16716 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16717 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16718 | |
| 16719 | HttpRequestInfo request; |
| 16720 | request.method = "POST"; |
| 16721 | request.url = GURL("http://www.foo.com/"); |
| 16722 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16723 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16724 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16725 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16726 | // Send headers successfully, but get an error while sending the body. |
| 16727 | MockWrite data_writes[] = { |
| 16728 | MockWrite("POST / HTTP/1.1\r\n" |
| 16729 | "Host: www.foo.com\r\n" |
| 16730 | "Connection: keep-alive\r\n" |
| 16731 | "Content-Length: 3\r\n\r\n"), |
| 16732 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16733 | }; |
| 16734 | |
| 16735 | MockRead data_reads[] = { |
| 16736 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 16737 | MockRead("hello world"), |
| 16738 | MockRead(SYNCHRONOUS, OK), |
| 16739 | }; |
| 16740 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16741 | arraysize(data_writes)); |
| 16742 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16743 | |
| 16744 | TestCompletionCallback callback; |
| 16745 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16746 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16748 | |
| 16749 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16750 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16751 | } |
| 16752 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16753 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16754 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16755 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16756 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16757 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16758 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16759 | |
| 16760 | HttpRequestInfo request; |
| 16761 | request.method = "POST"; |
| 16762 | request.url = GURL("http://www.foo.com/"); |
| 16763 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16764 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16765 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16766 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16767 | // Send headers successfully, but get an error while sending the body. |
| 16768 | MockWrite data_writes[] = { |
| 16769 | MockWrite("POST / HTTP/1.1\r\n" |
| 16770 | "Host: www.foo.com\r\n" |
| 16771 | "Connection: keep-alive\r\n" |
| 16772 | "Content-Length: 3\r\n\r\n"), |
| 16773 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16774 | }; |
| 16775 | |
| 16776 | MockRead data_reads[] = { |
| 16777 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16778 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16779 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16780 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16781 | MockRead(SYNCHRONOUS, OK), |
| 16782 | }; |
| 16783 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16784 | arraysize(data_writes)); |
| 16785 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16786 | |
| 16787 | TestCompletionCallback callback; |
| 16788 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16789 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16790 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16791 | |
| 16792 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16793 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16794 | } |
| 16795 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16796 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16797 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16798 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16799 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16800 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16801 | |
| 16802 | HttpRequestInfo request; |
| 16803 | request.method = "POST"; |
| 16804 | request.url = GURL("http://www.foo.com/"); |
| 16805 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16806 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16807 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16808 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16809 | // Send headers successfully, but get an error while sending the body. |
| 16810 | MockWrite data_writes[] = { |
| 16811 | MockWrite("POST / HTTP/1.1\r\n" |
| 16812 | "Host: www.foo.com\r\n" |
| 16813 | "Connection: keep-alive\r\n" |
| 16814 | "Content-Length: 3\r\n\r\n"), |
| 16815 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16816 | }; |
| 16817 | |
| 16818 | MockRead data_reads[] = { |
| 16819 | MockRead("HTTP 0.9 rocks!"), |
| 16820 | MockRead(SYNCHRONOUS, OK), |
| 16821 | }; |
| 16822 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16823 | arraysize(data_writes)); |
| 16824 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16825 | |
| 16826 | TestCompletionCallback callback; |
| 16827 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16828 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16829 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16830 | |
| 16831 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16832 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16833 | } |
| 16834 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16835 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16836 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16837 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16838 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16839 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16840 | |
| 16841 | HttpRequestInfo request; |
| 16842 | request.method = "POST"; |
| 16843 | request.url = GURL("http://www.foo.com/"); |
| 16844 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16845 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16846 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16847 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16848 | // Send headers successfully, but get an error while sending the body. |
| 16849 | MockWrite data_writes[] = { |
| 16850 | MockWrite("POST / HTTP/1.1\r\n" |
| 16851 | "Host: www.foo.com\r\n" |
| 16852 | "Connection: keep-alive\r\n" |
| 16853 | "Content-Length: 3\r\n\r\n"), |
| 16854 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16855 | }; |
| 16856 | |
| 16857 | MockRead data_reads[] = { |
| 16858 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16859 | MockRead(SYNCHRONOUS, OK), |
| 16860 | }; |
| 16861 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16862 | arraysize(data_writes)); |
| 16863 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16864 | |
| 16865 | TestCompletionCallback callback; |
| 16866 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16867 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16868 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16869 | |
| 16870 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16871 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16872 | } |
| 16873 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16874 | // Verify that proxy headers are not sent to the destination server when |
| 16875 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16876 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16877 | HttpRequestInfo request; |
| 16878 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16879 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16880 | AddWebSocketHeaders(&request.extra_headers); |
| 16881 | |
| 16882 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 16883 | session_deps_.proxy_resolution_service = |
| 16884 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16885 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16886 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16887 | |
| 16888 | // Since a proxy is configured, try to establish a tunnel. |
| 16889 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16890 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16891 | "Host: www.example.org:443\r\n" |
| 16892 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16893 | |
| 16894 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16895 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16896 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16897 | "Host: www.example.org:443\r\n" |
| 16898 | "Proxy-Connection: keep-alive\r\n" |
| 16899 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16900 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16901 | MockWrite("GET / HTTP/1.1\r\n" |
| 16902 | "Host: www.example.org\r\n" |
| 16903 | "Connection: Upgrade\r\n" |
| 16904 | "Upgrade: websocket\r\n" |
| 16905 | "Origin: http://www.example.org\r\n" |
| 16906 | "Sec-WebSocket-Version: 13\r\n" |
| 16907 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16908 | }; |
| 16909 | |
| 16910 | // The proxy responds to the connect with a 407, using a persistent |
| 16911 | // connection. |
| 16912 | MockRead data_reads[] = { |
| 16913 | // No credentials. |
| 16914 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16915 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16916 | MockRead("Content-Length: 0\r\n"), |
| 16917 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16918 | |
| 16919 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16920 | |
| 16921 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16922 | MockRead("Upgrade: websocket\r\n"), |
| 16923 | MockRead("Connection: Upgrade\r\n"), |
| 16924 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16925 | }; |
| 16926 | |
| 16927 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16928 | arraysize(data_writes)); |
| 16929 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16930 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16931 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16932 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16933 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16934 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16935 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16936 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16937 | &websocket_stream_create_helper); |
| 16938 | |
| 16939 | { |
| 16940 | TestCompletionCallback callback; |
| 16941 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16942 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16943 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16944 | |
| 16945 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16946 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16947 | } |
| 16948 | |
| 16949 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16950 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16951 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16952 | EXPECT_EQ(407, response->headers->response_code()); |
| 16953 | |
| 16954 | { |
| 16955 | TestCompletionCallback callback; |
| 16956 | |
| 16957 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16958 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16960 | |
| 16961 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16962 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16963 | } |
| 16964 | |
| 16965 | response = trans->GetResponseInfo(); |
| 16966 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16967 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16968 | |
| 16969 | EXPECT_EQ(101, response->headers->response_code()); |
| 16970 | |
| 16971 | trans.reset(); |
| 16972 | session->CloseAllConnections(); |
| 16973 | } |
| 16974 | |
| 16975 | // Verify that proxy headers are not sent to the destination server when |
| 16976 | // establishing a tunnel for an insecure WebSocket connection. |
| 16977 | // This requires the authentication info to be injected into the auth cache |
| 16978 | // due to crbug.com/395064 |
| 16979 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16980 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16981 | HttpRequestInfo request; |
| 16982 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16983 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16984 | AddWebSocketHeaders(&request.extra_headers); |
| 16985 | |
| 16986 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 16987 | session_deps_.proxy_resolution_service = |
| 16988 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16989 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16990 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16991 | |
| 16992 | MockWrite data_writes[] = { |
| 16993 | // Try to establish a tunnel for the WebSocket connection, with |
| 16994 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16995 | // they cannot and will not use the same TCP/IP connection as the |
| 16996 | // preflight HTTP request. |
| 16997 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16998 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16999 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17000 | "Proxy-Connection: keep-alive\r\n" |
| 17001 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 17002 | |
| 17003 | MockWrite( |
| 17004 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17005 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17006 | "Connection: Upgrade\r\n" |
| 17007 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17008 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17009 | "Sec-WebSocket-Version: 13\r\n" |
| 17010 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 17011 | }; |
| 17012 | |
| 17013 | MockRead data_reads[] = { |
| 17014 | // HTTP CONNECT with credentials. |
| 17015 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17016 | |
| 17017 | // WebSocket connection established inside tunnel. |
| 17018 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 17019 | MockRead("Upgrade: websocket\r\n"), |
| 17020 | MockRead("Connection: Upgrade\r\n"), |
| 17021 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 17022 | }; |
| 17023 | |
| 17024 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17025 | arraysize(data_writes)); |
| 17026 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17027 | |
| 17028 | session->http_auth_cache()->Add( |
| 17029 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17030 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17031 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17032 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17033 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17034 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 17035 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17036 | &websocket_stream_create_helper); |
| 17037 | |
| 17038 | TestCompletionCallback callback; |
| 17039 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17040 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17041 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17042 | |
| 17043 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17044 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17045 | |
| 17046 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17047 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17048 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17049 | |
| 17050 | EXPECT_EQ(101, response->headers->response_code()); |
| 17051 | |
| 17052 | trans.reset(); |
| 17053 | session->CloseAllConnections(); |
| 17054 | } |
| 17055 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17056 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17057 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17058 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17059 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17060 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17061 | |
| 17062 | HttpRequestInfo request; |
| 17063 | request.method = "POST"; |
| 17064 | request.url = GURL("http://www.foo.com/"); |
| 17065 | request.upload_data_stream = &upload_data_stream; |
| 17066 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17067 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17068 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17069 | MockWrite data_writes[] = { |
| 17070 | MockWrite("POST / HTTP/1.1\r\n" |
| 17071 | "Host: www.foo.com\r\n" |
| 17072 | "Connection: keep-alive\r\n" |
| 17073 | "Content-Length: 3\r\n\r\n"), |
| 17074 | MockWrite("foo"), |
| 17075 | }; |
| 17076 | |
| 17077 | MockRead data_reads[] = { |
| 17078 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17079 | MockRead(SYNCHRONOUS, OK), |
| 17080 | }; |
| 17081 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17082 | arraysize(data_writes)); |
| 17083 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17084 | |
| 17085 | TestCompletionCallback callback; |
| 17086 | |
| 17087 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17088 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17089 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17090 | |
| 17091 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17092 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17093 | |
| 17094 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17095 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17096 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17097 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17098 | } |
| 17099 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17100 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17101 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17102 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17103 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17104 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17105 | |
| 17106 | HttpRequestInfo request; |
| 17107 | request.method = "POST"; |
| 17108 | request.url = GURL("http://www.foo.com/"); |
| 17109 | request.upload_data_stream = &upload_data_stream; |
| 17110 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17111 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17112 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17113 | MockWrite data_writes[] = { |
| 17114 | MockWrite("POST / HTTP/1.1\r\n" |
| 17115 | "Host: www.foo.com\r\n" |
| 17116 | "Connection: keep-alive\r\n" |
| 17117 | "Content-Length: 3\r\n\r\n"), |
| 17118 | MockWrite("foo"), |
| 17119 | }; |
| 17120 | |
| 17121 | MockRead data_reads[] = { |
| 17122 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17123 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17124 | MockRead(SYNCHRONOUS, OK), |
| 17125 | }; |
| 17126 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17127 | arraysize(data_writes)); |
| 17128 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17129 | |
| 17130 | TestCompletionCallback callback; |
| 17131 | |
| 17132 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17133 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17134 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17135 | |
| 17136 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17137 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17138 | |
| 17139 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17140 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17141 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17142 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17143 | } |
| 17144 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17145 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17146 | ChunkedUploadDataStream upload_data_stream(0); |
| 17147 | |
| 17148 | HttpRequestInfo request; |
| 17149 | request.method = "POST"; |
| 17150 | request.url = GURL("http://www.foo.com/"); |
| 17151 | request.upload_data_stream = &upload_data_stream; |
| 17152 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17153 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17154 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17155 | // Send headers successfully, but get an error while sending the body. |
| 17156 | MockWrite data_writes[] = { |
| 17157 | MockWrite("POST / HTTP/1.1\r\n" |
| 17158 | "Host: www.foo.com\r\n" |
| 17159 | "Connection: keep-alive\r\n" |
| 17160 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17161 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17162 | }; |
| 17163 | |
| 17164 | MockRead data_reads[] = { |
| 17165 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17166 | MockRead(SYNCHRONOUS, OK), |
| 17167 | }; |
| 17168 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17169 | arraysize(data_writes)); |
| 17170 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17171 | |
| 17172 | TestCompletionCallback callback; |
| 17173 | |
| 17174 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17175 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17176 | |
| 17177 | base::RunLoop().RunUntilIdle(); |
| 17178 | upload_data_stream.AppendData("f", 1, false); |
| 17179 | |
| 17180 | base::RunLoop().RunUntilIdle(); |
| 17181 | upload_data_stream.AppendData("oo", 2, true); |
| 17182 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17183 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17184 | |
| 17185 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17186 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17187 | |
| 17188 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17189 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17190 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17191 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17192 | } |
| 17193 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17194 | // Confirm that transactions whose throttle is created in (and stays in) |
| 17195 | // the unthrottled state are not blocked. |
| 17196 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 17197 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17198 | std::unique_ptr<HttpNetworkSession> session( |
| 17199 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17200 | |
| 17201 | // Send a simple request and make sure it goes through. |
| 17202 | HttpRequestInfo request; |
| 17203 | request.method = "GET"; |
| 17204 | request.url = GURL("http://www.example.org/"); |
| 17205 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17206 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17207 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17208 | |
| 17209 | MockWrite data_writes[] = { |
| 17210 | MockWrite("GET / HTTP/1.1\r\n" |
| 17211 | "Host: www.example.org\r\n" |
| 17212 | "Connection: keep-alive\r\n\r\n"), |
| 17213 | }; |
| 17214 | MockRead data_reads[] = { |
| 17215 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17216 | MockRead(SYNCHRONOUS, OK), |
| 17217 | }; |
| 17218 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17219 | arraysize(data_writes)); |
| 17220 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17221 | |
| 17222 | TestCompletionCallback callback; |
| 17223 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17224 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17225 | } |
| 17226 | |
| 17227 | // Confirm requests can be blocked by a throttler, and are resumed |
| 17228 | // when the throttle is unblocked. |
| 17229 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 17230 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17231 | std::unique_ptr<HttpNetworkSession> session( |
| 17232 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17233 | |
| 17234 | // Send a simple request and make sure it goes through. |
| 17235 | HttpRequestInfo request; |
| 17236 | request.method = "GET"; |
| 17237 | request.url = GURL("http://www.example.org/"); |
| 17238 | |
| 17239 | MockWrite data_writes[] = { |
| 17240 | MockWrite("GET / HTTP/1.1\r\n" |
| 17241 | "Host: www.example.org\r\n" |
| 17242 | "Connection: keep-alive\r\n\r\n"), |
| 17243 | }; |
| 17244 | MockRead data_reads[] = { |
| 17245 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17246 | MockRead(SYNCHRONOUS, OK), |
| 17247 | }; |
| 17248 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17249 | arraysize(data_writes)); |
| 17250 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17251 | |
| 17252 | // Start a request that will be throttled at start; confirm it |
| 17253 | // doesn't complete. |
| 17254 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17255 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17256 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17257 | |
| 17258 | TestCompletionCallback callback; |
| 17259 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17260 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17261 | |
| 17262 | base::RunLoop().RunUntilIdle(); |
| 17263 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17264 | EXPECT_FALSE(callback.have_result()); |
| 17265 | |
| 17266 | // Confirm the request goes on to complete when unthrottled. |
| 17267 | throttler->UnthrottleAllRequests(); |
| 17268 | base::RunLoop().RunUntilIdle(); |
| 17269 | ASSERT_TRUE(callback.have_result()); |
| 17270 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17271 | } |
| 17272 | |
| 17273 | // Destroy a request while it's throttled. |
| 17274 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 17275 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17276 | std::unique_ptr<HttpNetworkSession> session( |
| 17277 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17278 | |
| 17279 | // Send a simple request and make sure it goes through. |
| 17280 | HttpRequestInfo request; |
| 17281 | request.method = "GET"; |
| 17282 | request.url = GURL("http://www.example.org/"); |
| 17283 | |
| 17284 | MockWrite data_writes[] = { |
| 17285 | MockWrite("GET / HTTP/1.1\r\n" |
| 17286 | "Host: www.example.org\r\n" |
| 17287 | "Connection: keep-alive\r\n\r\n"), |
| 17288 | }; |
| 17289 | MockRead data_reads[] = { |
| 17290 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17291 | MockRead(SYNCHRONOUS, OK), |
| 17292 | }; |
| 17293 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17294 | arraysize(data_writes)); |
| 17295 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17296 | |
| 17297 | // Start a request that will be throttled at start; confirm it |
| 17298 | // doesn't complete. |
| 17299 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17300 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17301 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17302 | |
| 17303 | TestCompletionCallback callback; |
| 17304 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17305 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17306 | |
| 17307 | base::RunLoop().RunUntilIdle(); |
| 17308 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17309 | EXPECT_FALSE(callback.have_result()); |
| 17310 | |
| 17311 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 17312 | trans.reset(); |
| 17313 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 17314 | } |
| 17315 | |
| 17316 | // Confirm the throttler receives SetPriority calls. |
| 17317 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 17318 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17319 | std::unique_ptr<HttpNetworkSession> session( |
| 17320 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17321 | |
| 17322 | // Send a simple request and make sure it goes through. |
| 17323 | HttpRequestInfo request; |
| 17324 | request.method = "GET"; |
| 17325 | request.url = GURL("http://www.example.org/"); |
| 17326 | |
| 17327 | MockWrite data_writes[] = { |
| 17328 | MockWrite("GET / HTTP/1.1\r\n" |
| 17329 | "Host: www.example.org\r\n" |
| 17330 | "Connection: keep-alive\r\n\r\n"), |
| 17331 | }; |
| 17332 | MockRead data_reads[] = { |
| 17333 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17334 | MockRead(SYNCHRONOUS, OK), |
| 17335 | }; |
| 17336 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17337 | arraysize(data_writes)); |
| 17338 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17339 | |
| 17340 | throttler->set_throttle_new_requests(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17341 | auto trans = std::make_unique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17342 | // Start the transaction to associate a throttle with it. |
| 17343 | TestCompletionCallback callback; |
| 17344 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17345 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17346 | |
| 17347 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 17348 | trans->SetPriority(LOW); |
| 17349 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 17350 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 17351 | |
| 17352 | throttler->UnthrottleAllRequests(); |
| 17353 | base::RunLoop().RunUntilIdle(); |
| 17354 | ASSERT_TRUE(callback.have_result()); |
| 17355 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17356 | } |
| 17357 | |
| 17358 | // Confirm that unthrottling from a SetPriority call by the |
| 17359 | // throttler works properly. |
| 17360 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 17361 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17362 | std::unique_ptr<HttpNetworkSession> session( |
| 17363 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17364 | |
| 17365 | // Send a simple request and make sure it goes through. |
| 17366 | HttpRequestInfo request; |
| 17367 | request.method = "GET"; |
| 17368 | request.url = GURL("http://www.example.org/"); |
| 17369 | |
| 17370 | MockWrite data_writes[] = { |
| 17371 | MockWrite("GET / HTTP/1.1\r\n" |
| 17372 | "Host: www.example.org\r\n" |
| 17373 | "Connection: keep-alive\r\n\r\n"), |
| 17374 | }; |
| 17375 | MockRead data_reads[] = { |
| 17376 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17377 | MockRead(SYNCHRONOUS, OK), |
| 17378 | }; |
| 17379 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17380 | arraysize(data_writes)); |
| 17381 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17382 | |
| 17383 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17384 | data_writes, arraysize(data_writes)); |
| 17385 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17386 | |
| 17387 | // Start a request that will be throttled at start; confirm it |
| 17388 | // doesn't complete. |
| 17389 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17390 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17391 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17392 | |
| 17393 | TestCompletionCallback callback; |
| 17394 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17395 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17396 | |
| 17397 | base::RunLoop().RunUntilIdle(); |
| 17398 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17399 | EXPECT_FALSE(callback.have_result()); |
| 17400 | |
| 17401 | // Create a new request, call SetPriority on it to unthrottle, |
| 17402 | // and make sure that allows the original request to complete. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17403 | auto trans1 = std::make_unique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17404 | throttler->set_priority_change_closure( |
| 17405 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 17406 | base::Unretained(throttler))); |
| 17407 | |
| 17408 | // Start the transaction to associate a throttle with it. |
| 17409 | TestCompletionCallback callback1; |
| 17410 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 17411 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17412 | |
| 17413 | trans1->SetPriority(IDLE); |
| 17414 | |
| 17415 | base::RunLoop().RunUntilIdle(); |
| 17416 | ASSERT_TRUE(callback.have_result()); |
| 17417 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17418 | ASSERT_TRUE(callback1.have_result()); |
| 17419 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 17420 | } |
| 17421 | |
| 17422 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17423 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17424 | |
| 17425 | // Confirm that destroying a transaction from a SetPriority call by the |
| 17426 | // throttler works properly. |
| 17427 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 17428 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17429 | std::unique_ptr<HttpNetworkSession> session( |
| 17430 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17431 | |
| 17432 | // Send a simple request and make sure it goes through. |
| 17433 | HttpRequestInfo request; |
| 17434 | request.method = "GET"; |
| 17435 | request.url = GURL("http://www.example.org/"); |
| 17436 | |
| 17437 | MockWrite data_writes[] = { |
| 17438 | MockWrite("GET / HTTP/1.1\r\n" |
| 17439 | "Host: www.example.org\r\n" |
| 17440 | "Connection: keep-alive\r\n\r\n"), |
| 17441 | }; |
| 17442 | MockRead data_reads[] = { |
| 17443 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17444 | MockRead(SYNCHRONOUS, OK), |
| 17445 | }; |
| 17446 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17447 | arraysize(data_writes)); |
| 17448 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17449 | |
| 17450 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17451 | data_writes, arraysize(data_writes)); |
| 17452 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17453 | |
| 17454 | // Start a request that will be throttled at start; confirm it |
| 17455 | // doesn't complete. |
| 17456 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17457 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17458 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17459 | |
| 17460 | TestCompletionCallback callback; |
| 17461 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17462 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17463 | |
| 17464 | base::RunLoop().RunUntilIdle(); |
| 17465 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17466 | EXPECT_FALSE(callback.have_result()); |
| 17467 | |
| 17468 | // Arrange for the set priority call on the above transaction to delete |
| 17469 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17470 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17471 | throttler->set_priority_change_closure( |
| 17472 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 17473 | |
| 17474 | // Call it and check results (partially a "doesn't crash" test). |
| 17475 | trans_ptr->SetPriority(IDLE); |
| 17476 | trans_ptr = nullptr; // No longer a valid pointer. |
| 17477 | |
| 17478 | base::RunLoop().RunUntilIdle(); |
| 17479 | ASSERT_FALSE(callback.have_result()); |
| 17480 | } |
| 17481 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17482 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17483 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17484 | const std::string https_url = "https://www.example.com"; |
| 17485 | HttpRequestInfo request; |
| 17486 | request.url = GURL(https_url); |
| 17487 | request.method = "GET"; |
| 17488 | |
| 17489 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17490 | ssl.ssl_info.token_binding_negotiated = true; |
| 17491 | ssl.ssl_info.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17492 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17493 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17494 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17495 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17496 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 17497 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17498 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 17499 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 17500 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17501 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17502 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17503 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17504 | |
| 17505 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17506 | TestCompletionCallback callback; |
| 17507 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17508 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17509 | |
| 17510 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17511 | |
| 17512 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17513 | HttpRequestHeaders headers; |
| 17514 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17515 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17516 | } |
| 17517 | #endif // !defined(OS_IOS) |
| 17518 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17519 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17520 | const std::string& accept_encoding, |
| 17521 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17522 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17523 | bool should_match) { |
| 17524 | HttpRequestInfo request; |
| 17525 | request.method = "GET"; |
| 17526 | request.url = GURL("http://www.foo.com/"); |
| 17527 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17528 | accept_encoding); |
| 17529 | |
| 17530 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17531 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17532 | // Send headers successfully, but get an error while sending the body. |
| 17533 | MockWrite data_writes[] = { |
| 17534 | MockWrite("GET / HTTP/1.1\r\n" |
| 17535 | "Host: www.foo.com\r\n" |
| 17536 | "Connection: keep-alive\r\n" |
| 17537 | "Accept-Encoding: "), |
| 17538 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17539 | }; |
| 17540 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17541 | std::string response_code = "200 OK"; |
| 17542 | std::string extra; |
| 17543 | if (!location.empty()) { |
| 17544 | response_code = "301 Redirect\r\nLocation: "; |
| 17545 | response_code.append(location); |
| 17546 | } |
| 17547 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17548 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17549 | MockRead("HTTP/1.0 "), |
| 17550 | MockRead(response_code.data()), |
| 17551 | MockRead("\r\nContent-Encoding: "), |
| 17552 | MockRead(content_encoding.data()), |
| 17553 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17554 | MockRead(SYNCHRONOUS, OK), |
| 17555 | }; |
| 17556 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17557 | arraysize(data_writes)); |
| 17558 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17559 | |
| 17560 | TestCompletionCallback callback; |
| 17561 | |
| 17562 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17563 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17564 | |
| 17565 | rv = callback.WaitForResult(); |
| 17566 | if (should_match) { |
| 17567 | EXPECT_THAT(rv, IsOk()); |
| 17568 | } else { |
| 17569 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17570 | } |
| 17571 | } |
| 17572 | |
| 17573 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17574 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17575 | } |
| 17576 | |
| 17577 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17578 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17579 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17580 | } |
| 17581 | |
| 17582 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17583 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17584 | "", false); |
| 17585 | } |
| 17586 | |
| 17587 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17588 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17589 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17590 | } |
| 17591 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17592 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17593 | ProxyConfig proxy_config; |
| 17594 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17595 | proxy_config.set_pac_mandatory(true); |
| 17596 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 17597 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17598 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 17599 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17600 | |
| 17601 | HttpRequestInfo request; |
| 17602 | request.method = "GET"; |
| 17603 | request.url = GURL("http://www.example.org/"); |
| 17604 | |
| 17605 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17606 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17607 | |
| 17608 | TestCompletionCallback callback; |
| 17609 | |
| 17610 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17611 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17612 | EXPECT_THAT(callback.WaitForResult(), |
| 17613 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17614 | } |
| 17615 | |
| 17616 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17617 | ProxyConfig proxy_config; |
| 17618 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17619 | proxy_config.set_pac_mandatory(true); |
| 17620 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17621 | new MockAsyncProxyResolverFactory(false); |
| 17622 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 17623 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
| 17624 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
| 17625 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17626 | HttpRequestInfo request; |
| 17627 | request.method = "GET"; |
| 17628 | request.url = GURL("http://www.example.org/"); |
| 17629 | |
| 17630 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17631 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17632 | |
| 17633 | TestCompletionCallback callback; |
| 17634 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17635 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17636 | |
| 17637 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17638 | ERR_FAILED, &resolver); |
| 17639 | EXPECT_THAT(callback.WaitForResult(), |
| 17640 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17641 | } |
| 17642 | |
| 17643 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame^] | 17644 | session_deps_.proxy_resolution_service = |
| 17645 | ProxyResolutionService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17646 | session_deps_.enable_quic = false; |
| 17647 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17648 | |
| 17649 | HttpRequestInfo request; |
| 17650 | request.method = "GET"; |
| 17651 | request.url = GURL("http://www.example.org/"); |
| 17652 | |
| 17653 | TestCompletionCallback callback; |
| 17654 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17655 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17656 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17657 | |
| 17658 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17659 | } |
| 17660 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17661 | } // namespace net |