[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". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3034 | session_deps_.proxy_service = |
| 3035 | ProxyService::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". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3159 | session_deps_.proxy_service = |
| 3160 | ProxyService::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". |
| 3288 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3289 | BoundTestNetLog log; |
| 3290 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3291 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3292 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3293 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3294 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3295 | // Since we have proxy, should try to establish tunnel. |
| 3296 | MockWrite data_writes1[] = { |
| 3297 | MockWrite(ASYNC, 0, |
| 3298 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3299 | "Host: www.example.org:443\r\n" |
| 3300 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3301 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3302 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3303 | // be issuing -- the final header line contains the credentials. |
| 3304 | MockWrite(ASYNC, 3, |
| 3305 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3306 | "Host: www.example.org:443\r\n" |
| 3307 | "Proxy-Connection: keep-alive\r\n" |
| 3308 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3309 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3310 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3311 | // The proxy responds to the connect with a 407, using a persistent |
| 3312 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3313 | MockRead data_reads1[] = { |
| 3314 | // No credentials. |
| 3315 | MockRead(ASYNC, 1, |
| 3316 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3317 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3318 | "Proxy-Connection: keep-alive\r\n" |
| 3319 | "Content-Length: 10\r\n\r\n"), |
| 3320 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3321 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3322 | // Wrong credentials (wrong password). |
| 3323 | MockRead(ASYNC, 4, |
| 3324 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3325 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3326 | "Proxy-Connection: keep-alive\r\n" |
| 3327 | "Content-Length: 10\r\n\r\n"), |
| 3328 | // No response body because the test stops reading here. |
| 3329 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3330 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3331 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3332 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3333 | arraysize(data_writes1)); |
| 3334 | data1.set_busy_before_sync_reads(true); |
| 3335 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3336 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3337 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3338 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3339 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3340 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3341 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3342 | TestNetLogEntry::List entries; |
| 3343 | log.GetEntries(&entries); |
| 3344 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3345 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3346 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3347 | ExpectLogContainsSomewhere( |
| 3348 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3349 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3350 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3351 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3352 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3353 | ASSERT_TRUE(response); |
| 3354 | ASSERT_TRUE(response->headers); |
| 3355 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3356 | EXPECT_EQ(407, response->headers->response_code()); |
| 3357 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3358 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3359 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3360 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3361 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3362 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3363 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3364 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3365 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3366 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3367 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3368 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3369 | ASSERT_TRUE(response); |
| 3370 | ASSERT_TRUE(response->headers); |
| 3371 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3372 | EXPECT_EQ(407, response->headers->response_code()); |
| 3373 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3374 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3375 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3376 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3377 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3378 | // out of scope. |
| 3379 | session->CloseAllConnections(); |
| 3380 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3384 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3385 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3386 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3387 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3388 | // reused. See http://crbug.com/544255. |
| 3389 | for (int i = 0; i < 2; ++i) { |
| 3390 | HttpRequestInfo request; |
| 3391 | request.method = "GET"; |
| 3392 | request.url = GURL("https://www.example.org/"); |
| 3393 | // Ensure that proxy authentication is attempted even |
| 3394 | // when the no authentication data flag is set. |
| 3395 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3396 | |
| 3397 | // Configure against proxy server "myproxy:70". |
| 3398 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3399 | BoundTestNetLog log; |
| 3400 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3401 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3402 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3403 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3404 | |
| 3405 | // Since we have proxy, should try to establish tunnel. |
| 3406 | MockWrite data_writes1[] = { |
| 3407 | MockWrite(ASYNC, 0, |
| 3408 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3409 | "Host: www.example.org:443\r\n" |
| 3410 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3411 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3412 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3413 | // be issuing -- the final header line contains the credentials. |
| 3414 | MockWrite(ASYNC, 3, |
| 3415 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3416 | "Host: www.example.org:443\r\n" |
| 3417 | "Proxy-Connection: keep-alive\r\n" |
| 3418 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3419 | }; |
| 3420 | |
| 3421 | // The proxy responds to the connect with a 407, using a persistent |
| 3422 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3423 | MockRead data_reads1[] = { |
| 3424 | // No credentials. |
| 3425 | MockRead(ASYNC, 1, |
| 3426 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3427 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3428 | "Content-Length: 10\r\n\r\n"), |
| 3429 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3430 | |
| 3431 | // Wrong credentials (wrong password). |
| 3432 | MockRead(ASYNC, 4, |
| 3433 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3434 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3435 | "Content-Length: 10\r\n\r\n"), |
| 3436 | // No response body because the test stops reading here. |
| 3437 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3438 | }; |
| 3439 | |
| 3440 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3441 | arraysize(data_writes1)); |
| 3442 | data1.set_busy_before_sync_reads(true); |
| 3443 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3444 | |
| 3445 | TestCompletionCallback callback1; |
| 3446 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3447 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3448 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3449 | |
| 3450 | TestNetLogEntry::List entries; |
| 3451 | log.GetEntries(&entries); |
| 3452 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3453 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3454 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3455 | ExpectLogContainsSomewhere( |
| 3456 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3457 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3458 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3459 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3460 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3461 | ASSERT_TRUE(response); |
| 3462 | ASSERT_TRUE(response->headers); |
| 3463 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3464 | EXPECT_EQ(407, response->headers->response_code()); |
| 3465 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3466 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3467 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3468 | |
| 3469 | TestCompletionCallback callback2; |
| 3470 | |
| 3471 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3472 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3473 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3474 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3475 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3476 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3477 | ASSERT_TRUE(response); |
| 3478 | ASSERT_TRUE(response->headers); |
| 3479 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3480 | EXPECT_EQ(407, response->headers->response_code()); |
| 3481 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3482 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3483 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3484 | |
| 3485 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3486 | // out of scope. |
| 3487 | session->CloseAllConnections(); |
| 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3492 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3493 | // the case the server sends extra data on the original socket, so it can't be |
| 3494 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3495 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3496 | HttpRequestInfo request; |
| 3497 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3498 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3499 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3500 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3501 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3502 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3503 | session_deps_.proxy_service = |
| 3504 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3505 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3506 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3507 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3508 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3509 | // Since we have proxy, should try to establish tunnel. |
| 3510 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3511 | MockWrite(ASYNC, 0, |
| 3512 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3513 | "Host: www.example.org:443\r\n" |
| 3514 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3515 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3516 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3517 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3518 | // extra data, so the socket cannot be reused. |
| 3519 | MockRead data_reads1[] = { |
| 3520 | // No credentials. |
| 3521 | MockRead(ASYNC, 1, |
| 3522 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3523 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3524 | "Content-Length: 10\r\n\r\n"), |
| 3525 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3526 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3527 | }; |
| 3528 | |
| 3529 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3530 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3531 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3532 | MockWrite(ASYNC, 0, |
| 3533 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3534 | "Host: www.example.org:443\r\n" |
| 3535 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3536 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3537 | |
| 3538 | MockWrite(ASYNC, 2, |
| 3539 | "GET / HTTP/1.1\r\n" |
| 3540 | "Host: www.example.org\r\n" |
| 3541 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3542 | }; |
| 3543 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3544 | MockRead data_reads2[] = { |
| 3545 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3546 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3547 | MockRead(ASYNC, 3, |
| 3548 | "HTTP/1.1 200 OK\r\n" |
| 3549 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3550 | "Content-Length: 5\r\n\r\n"), |
| 3551 | // No response body because the test stops reading here. |
| 3552 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3553 | }; |
| 3554 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3555 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3556 | arraysize(data_writes1)); |
| 3557 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3558 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3559 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3560 | arraysize(data_writes2)); |
| 3561 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3562 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3563 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3564 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3565 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3566 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3567 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3568 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3569 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3570 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3571 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3572 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3573 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3574 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3575 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3576 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3577 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3578 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3579 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3580 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3581 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3582 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3583 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3584 | ASSERT_TRUE(response); |
| 3585 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3586 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3587 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3588 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3589 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3590 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3591 | LoadTimingInfo load_timing_info; |
| 3592 | // CONNECT requests and responses are handled at the connect job level, so |
| 3593 | // the transaction does not yet have a connection. |
| 3594 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3596 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3597 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3598 | rv = |
| 3599 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3600 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3601 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3602 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3603 | EXPECT_EQ(200, response->headers->response_code()); |
| 3604 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3605 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3606 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3607 | // The password prompt info should not be set. |
| 3608 | EXPECT_FALSE(response->auth_challenge); |
| 3609 | |
| 3610 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3611 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3612 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3613 | |
| 3614 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3615 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3616 | } |
| 3617 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3618 | // Test the case a proxy closes a socket while the challenge body is being |
| 3619 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3620 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3621 | HttpRequestInfo request; |
| 3622 | request.method = "GET"; |
| 3623 | request.url = GURL("https://www.example.org/"); |
| 3624 | // Ensure that proxy authentication is attempted even |
| 3625 | // when the no authentication data flag is set. |
| 3626 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3627 | |
| 3628 | // Configure against proxy server "myproxy:70". |
| 3629 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3630 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3631 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3632 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3633 | |
| 3634 | // Since we have proxy, should try to establish tunnel. |
| 3635 | MockWrite data_writes1[] = { |
| 3636 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3637 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3638 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3639 | }; |
| 3640 | |
| 3641 | // The proxy responds to the connect with a 407, using a persistent |
| 3642 | // connection. |
| 3643 | MockRead data_reads1[] = { |
| 3644 | // No credentials. |
| 3645 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3646 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3647 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3648 | // Server hands up in the middle of the body. |
| 3649 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3650 | }; |
| 3651 | |
| 3652 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3653 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3654 | // be issuing -- the final header line contains the credentials. |
| 3655 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3656 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3657 | "Proxy-Connection: keep-alive\r\n" |
| 3658 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3659 | |
| 3660 | MockWrite("GET / HTTP/1.1\r\n" |
| 3661 | "Host: www.example.org\r\n" |
| 3662 | "Connection: keep-alive\r\n\r\n"), |
| 3663 | }; |
| 3664 | |
| 3665 | MockRead data_reads2[] = { |
| 3666 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3667 | |
| 3668 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3669 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3670 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3671 | MockRead(SYNCHRONOUS, "hello"), |
| 3672 | }; |
| 3673 | |
| 3674 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3675 | data_writes1, arraysize(data_writes1)); |
| 3676 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3677 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3678 | data_writes2, arraysize(data_writes2)); |
| 3679 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3680 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3681 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3682 | |
| 3683 | TestCompletionCallback callback; |
| 3684 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3685 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3686 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3687 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3688 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3689 | ASSERT_TRUE(response); |
| 3690 | ASSERT_TRUE(response->headers); |
| 3691 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3692 | EXPECT_EQ(407, response->headers->response_code()); |
| 3693 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3694 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3695 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3696 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3697 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3698 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3699 | ASSERT_TRUE(response); |
| 3700 | ASSERT_TRUE(response->headers); |
| 3701 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3702 | EXPECT_EQ(200, response->headers->response_code()); |
| 3703 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3704 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3705 | EXPECT_EQ("hello", body); |
| 3706 | } |
| 3707 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3708 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3709 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3710 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3711 | HttpRequestInfo request; |
| 3712 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3713 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3714 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3715 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3716 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3717 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3718 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3720 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3721 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3722 | // Since we have proxy, should try to establish tunnel. |
| 3723 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3724 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3725 | "Host: www.example.org:443\r\n" |
| 3726 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3727 | }; |
| 3728 | |
| 3729 | // The proxy responds to the connect with a 407. |
| 3730 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3731 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3732 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3733 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3734 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3735 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3736 | }; |
| 3737 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3738 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3739 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3740 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3741 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3742 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3743 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3744 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3745 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3746 | |
| 3747 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3748 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3749 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3750 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3751 | ASSERT_TRUE(response); |
| 3752 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3753 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3754 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3755 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3756 | |
| 3757 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3758 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3759 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3760 | |
| 3761 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3762 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3763 | } |
| 3764 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3765 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3766 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3767 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3768 | HttpRequestInfo request; |
| 3769 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3770 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3771 | |
| 3772 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3773 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3774 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3776 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3778 | |
| 3779 | // Since we have proxy, should try to establish tunnel. |
| 3780 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3781 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3782 | "Host: www.example.org:443\r\n" |
| 3783 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3784 | }; |
| 3785 | |
| 3786 | // The proxy responds to the connect with a 407. |
| 3787 | MockRead data_reads[] = { |
| 3788 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3789 | MockRead("X-Foo: bar\r\n"), |
| 3790 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3791 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3792 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3793 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3794 | }; |
| 3795 | |
| 3796 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3797 | arraysize(data_writes)); |
| 3798 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3799 | |
| 3800 | TestCompletionCallback callback; |
| 3801 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3802 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3803 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3804 | |
| 3805 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3806 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3807 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3808 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3809 | ASSERT_TRUE(response); |
| 3810 | ASSERT_TRUE(response->headers); |
| 3811 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3812 | EXPECT_EQ(407, response->headers->response_code()); |
| 3813 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3814 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3815 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3816 | |
| 3817 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3818 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3819 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3820 | |
| 3821 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3822 | session->CloseAllConnections(); |
| 3823 | } |
| 3824 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3825 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3826 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3827 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3828 | HttpRequestInfo request; |
| 3829 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3830 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3831 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3832 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3833 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3834 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3835 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3836 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3837 | MockWrite( |
| 3838 | "GET / HTTP/1.1\r\n" |
| 3839 | "Host: www.example.org\r\n" |
| 3840 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3841 | }; |
| 3842 | |
| 3843 | MockRead data_reads1[] = { |
| 3844 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3845 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3846 | // Large content-length -- won't matter, as connection will be reset. |
| 3847 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3848 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3849 | }; |
| 3850 | |
| 3851 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3852 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3853 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3854 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3855 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3856 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3857 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3859 | |
| 3860 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3861 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3862 | } |
| 3863 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3864 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3865 | // through a non-authenticating proxy. The request should fail with |
| 3866 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3867 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3868 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3869 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3870 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3871 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3872 | HttpRequestInfo request; |
| 3873 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3874 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3875 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3876 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3877 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3878 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3879 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3880 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3881 | // Since we have proxy, should try to establish tunnel. |
| 3882 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3883 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3884 | "Host: www.example.org:443\r\n" |
| 3885 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3886 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3887 | MockWrite("GET / HTTP/1.1\r\n" |
| 3888 | "Host: www.example.org\r\n" |
| 3889 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3890 | }; |
| 3891 | |
| 3892 | MockRead data_reads1[] = { |
| 3893 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3894 | |
| 3895 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3896 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3897 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3898 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3899 | }; |
| 3900 | |
| 3901 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3902 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3903 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3904 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3905 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3906 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3907 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3908 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3909 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3910 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3911 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3913 | |
| 3914 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3915 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3916 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3917 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3918 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3919 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3920 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3921 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3922 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3923 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3924 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3925 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3926 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3927 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3928 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3929 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3930 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3931 | HttpRequestInfo request; |
| 3932 | request.method = "GET"; |
| 3933 | request.url = GURL("https://www.example.org/"); |
| 3934 | |
| 3935 | // Configure against proxy server "myproxy:70". |
| 3936 | session_deps_.proxy_service = |
| 3937 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3938 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3939 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3940 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3941 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3942 | mock_handler->set_allows_default_credentials(true); |
| 3943 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3944 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3945 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3946 | |
| 3947 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3948 | NetLog net_log; |
| 3949 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3950 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3951 | |
| 3952 | // Since we have proxy, should try to establish tunnel. |
| 3953 | MockWrite data_writes1[] = { |
| 3954 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3955 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3956 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3957 | }; |
| 3958 | |
| 3959 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3960 | // connection. |
| 3961 | MockRead data_reads1[] = { |
| 3962 | // No credentials. |
| 3963 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3964 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3965 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3966 | }; |
| 3967 | |
| 3968 | // Since the first connection couldn't be reused, need to establish another |
| 3969 | // once given credentials. |
| 3970 | MockWrite data_writes2[] = { |
| 3971 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3972 | // be issuing -- the final header line contains the credentials. |
| 3973 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3974 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3975 | "Proxy-Connection: keep-alive\r\n" |
| 3976 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3977 | |
| 3978 | MockWrite("GET / HTTP/1.1\r\n" |
| 3979 | "Host: www.example.org\r\n" |
| 3980 | "Connection: keep-alive\r\n\r\n"), |
| 3981 | }; |
| 3982 | |
| 3983 | MockRead data_reads2[] = { |
| 3984 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3985 | |
| 3986 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3987 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3988 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3989 | MockRead(SYNCHRONOUS, "hello"), |
| 3990 | }; |
| 3991 | |
| 3992 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3993 | data_writes1, arraysize(data_writes1)); |
| 3994 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3995 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3996 | data_writes2, arraysize(data_writes2)); |
| 3997 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3998 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3999 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4000 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4001 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4002 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4003 | |
| 4004 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4005 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4006 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4007 | |
| 4008 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4009 | ASSERT_TRUE(response); |
| 4010 | ASSERT_TRUE(response->headers); |
| 4011 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4012 | EXPECT_EQ(407, response->headers->response_code()); |
| 4013 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4014 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4015 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4016 | |
| 4017 | LoadTimingInfo load_timing_info; |
| 4018 | // CONNECT requests and responses are handled at the connect job level, so |
| 4019 | // the transaction does not yet have a connection. |
| 4020 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4021 | |
| 4022 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4023 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4024 | response = trans->GetResponseInfo(); |
| 4025 | ASSERT_TRUE(response); |
| 4026 | ASSERT_TRUE(response->headers); |
| 4027 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4028 | EXPECT_EQ(200, response->headers->response_code()); |
| 4029 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4030 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4031 | |
| 4032 | // The password prompt info should not be set. |
| 4033 | EXPECT_FALSE(response->auth_challenge); |
| 4034 | |
| 4035 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4036 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4037 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4038 | |
| 4039 | trans.reset(); |
| 4040 | session->CloseAllConnections(); |
| 4041 | } |
| 4042 | |
| 4043 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4044 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4045 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4046 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4047 | HttpRequestInfo request; |
| 4048 | request.method = "GET"; |
| 4049 | request.url = GURL("https://www.example.org/"); |
| 4050 | |
| 4051 | // Configure against proxy server "myproxy:70". |
| 4052 | session_deps_.proxy_service = |
| 4053 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4054 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4055 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4056 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4057 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4058 | mock_handler->set_allows_default_credentials(true); |
| 4059 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4060 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4061 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4062 | |
| 4063 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4064 | NetLog net_log; |
| 4065 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4066 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4067 | |
| 4068 | // Should try to establish tunnel. |
| 4069 | MockWrite data_writes1[] = { |
| 4070 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4071 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4072 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4073 | |
| 4074 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4075 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4076 | "Proxy-Connection: keep-alive\r\n" |
| 4077 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4078 | }; |
| 4079 | |
| 4080 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4081 | // connection. |
| 4082 | MockRead data_reads1[] = { |
| 4083 | // No credentials. |
| 4084 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4085 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4086 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4087 | }; |
| 4088 | |
| 4089 | // Since the first connection was closed, need to establish another once given |
| 4090 | // credentials. |
| 4091 | MockWrite data_writes2[] = { |
| 4092 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4093 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4094 | "Proxy-Connection: keep-alive\r\n" |
| 4095 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4096 | |
| 4097 | MockWrite("GET / HTTP/1.1\r\n" |
| 4098 | "Host: www.example.org\r\n" |
| 4099 | "Connection: keep-alive\r\n\r\n"), |
| 4100 | }; |
| 4101 | |
| 4102 | MockRead data_reads2[] = { |
| 4103 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4104 | |
| 4105 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4106 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4107 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4108 | MockRead(SYNCHRONOUS, "hello"), |
| 4109 | }; |
| 4110 | |
| 4111 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4112 | data_writes1, arraysize(data_writes1)); |
| 4113 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4114 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4115 | data_writes2, arraysize(data_writes2)); |
| 4116 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4117 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4118 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4119 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4120 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4121 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4122 | |
| 4123 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4124 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4125 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4126 | |
| 4127 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4128 | ASSERT_TRUE(response); |
| 4129 | ASSERT_TRUE(response->headers); |
| 4130 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4131 | EXPECT_EQ(407, response->headers->response_code()); |
| 4132 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4133 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4134 | EXPECT_FALSE(response->auth_challenge); |
| 4135 | |
| 4136 | LoadTimingInfo load_timing_info; |
| 4137 | // CONNECT requests and responses are handled at the connect job level, so |
| 4138 | // the transaction does not yet have a connection. |
| 4139 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4140 | |
| 4141 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4142 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4143 | |
| 4144 | response = trans->GetResponseInfo(); |
| 4145 | ASSERT_TRUE(response); |
| 4146 | ASSERT_TRUE(response->headers); |
| 4147 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4148 | EXPECT_EQ(200, response->headers->response_code()); |
| 4149 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4150 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4151 | |
| 4152 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4153 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4154 | |
| 4155 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4156 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4157 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4158 | |
| 4159 | trans.reset(); |
| 4160 | session->CloseAllConnections(); |
| 4161 | } |
| 4162 | |
| 4163 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4164 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4165 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4166 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4167 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4168 | HttpRequestInfo request; |
| 4169 | request.method = "GET"; |
| 4170 | request.url = GURL("https://www.example.org/"); |
| 4171 | |
| 4172 | // Configure against proxy server "myproxy:70". |
| 4173 | session_deps_.proxy_service = |
| 4174 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4175 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4176 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4177 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4178 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4179 | mock_handler->set_allows_default_credentials(true); |
| 4180 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4181 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4182 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4183 | |
| 4184 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4185 | NetLog net_log; |
| 4186 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4187 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4188 | |
| 4189 | // Should try to establish tunnel. |
| 4190 | MockWrite data_writes1[] = { |
| 4191 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4192 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4193 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4194 | |
| 4195 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4196 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4197 | "Proxy-Connection: keep-alive\r\n" |
| 4198 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4199 | }; |
| 4200 | |
| 4201 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4202 | // second request is sent. |
| 4203 | MockRead data_reads1[] = { |
| 4204 | // No credentials. |
| 4205 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4206 | MockRead("Content-Length: 0\r\n"), |
| 4207 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4208 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4209 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4210 | }; |
| 4211 | |
| 4212 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4213 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4214 | // request. |
| 4215 | MockWrite data_writes2[] = { |
| 4216 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4217 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4218 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4219 | }; |
| 4220 | |
| 4221 | // The proxy, having had more than enough of us, just hangs up. |
| 4222 | MockRead data_reads2[] = { |
| 4223 | // No credentials. |
| 4224 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4225 | }; |
| 4226 | |
| 4227 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4228 | data_writes1, arraysize(data_writes1)); |
| 4229 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4230 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4231 | data_writes2, arraysize(data_writes2)); |
| 4232 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4233 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4234 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4235 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4236 | |
| 4237 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4238 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4239 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4240 | |
| 4241 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4242 | ASSERT_TRUE(response); |
| 4243 | ASSERT_TRUE(response->headers); |
| 4244 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4245 | EXPECT_EQ(407, response->headers->response_code()); |
| 4246 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4247 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4248 | EXPECT_FALSE(response->auth_challenge); |
| 4249 | |
| 4250 | LoadTimingInfo load_timing_info; |
| 4251 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4252 | |
| 4253 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4254 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4255 | |
| 4256 | trans.reset(); |
| 4257 | session->CloseAllConnections(); |
| 4258 | } |
| 4259 | |
| 4260 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4261 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4262 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4263 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4264 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4265 | HttpRequestInfo request; |
| 4266 | request.method = "GET"; |
| 4267 | request.url = GURL("https://www.example.org/"); |
| 4268 | |
| 4269 | // Configure against proxy server "myproxy:70". |
| 4270 | session_deps_.proxy_service = |
| 4271 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4272 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4273 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4274 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4275 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4276 | mock_handler->set_allows_default_credentials(true); |
| 4277 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4278 | HttpAuth::AUTH_PROXY); |
| 4279 | // Add another handler for the second challenge. It supports default |
| 4280 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4281 | 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); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4285 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4286 | |
| 4287 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4288 | NetLog net_log; |
| 4289 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4290 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4291 | |
| 4292 | // Should try to establish tunnel. |
| 4293 | MockWrite data_writes1[] = { |
| 4294 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4295 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4296 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4297 | }; |
| 4298 | |
| 4299 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4300 | // connection. |
| 4301 | MockRead data_reads1[] = { |
| 4302 | // No credentials. |
| 4303 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4304 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4305 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4306 | }; |
| 4307 | |
| 4308 | // Since the first connection was closed, need to establish another once given |
| 4309 | // credentials. |
| 4310 | MockWrite data_writes2[] = { |
| 4311 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4312 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4313 | "Proxy-Connection: keep-alive\r\n" |
| 4314 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4315 | }; |
| 4316 | |
| 4317 | MockRead data_reads2[] = { |
| 4318 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4319 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4320 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4321 | }; |
| 4322 | |
| 4323 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4324 | data_writes1, arraysize(data_writes1)); |
| 4325 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4326 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4327 | data_writes2, arraysize(data_writes2)); |
| 4328 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4329 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4330 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4331 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4332 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4333 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4334 | |
| 4335 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4336 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4337 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4338 | |
| 4339 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4340 | ASSERT_TRUE(response); |
| 4341 | ASSERT_TRUE(response->headers); |
| 4342 | EXPECT_EQ(407, response->headers->response_code()); |
| 4343 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4344 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4345 | EXPECT_FALSE(response->auth_challenge); |
| 4346 | |
| 4347 | LoadTimingInfo load_timing_info; |
| 4348 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4349 | |
| 4350 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4351 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4352 | response = trans->GetResponseInfo(); |
| 4353 | ASSERT_TRUE(response); |
| 4354 | ASSERT_TRUE(response->headers); |
| 4355 | EXPECT_EQ(407, response->headers->response_code()); |
| 4356 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4357 | EXPECT_TRUE(response->auth_challenge); |
| 4358 | |
| 4359 | trans.reset(); |
| 4360 | session->CloseAllConnections(); |
| 4361 | } |
| 4362 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4363 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4364 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4365 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4366 | // authentication handshake can continue with the same scheme but with a |
| 4367 | // different identity. |
| 4368 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4369 | HttpRequestInfo request; |
| 4370 | request.method = "GET"; |
| 4371 | request.url = GURL("http://www.example.org/"); |
| 4372 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4373 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4374 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4375 | |
| 4376 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4377 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4378 | mock_handler->set_allows_default_credentials(true); |
| 4379 | mock_handler->set_allows_explicit_credentials(true); |
| 4380 | mock_handler->set_connection_based(true); |
| 4381 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4382 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4383 | HttpAuth::AUTH_SERVER); |
| 4384 | |
| 4385 | // Add another handler for the second challenge. It supports default |
| 4386 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4387 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4388 | mock_handler->set_allows_default_credentials(true); |
| 4389 | mock_handler->set_allows_explicit_credentials(true); |
| 4390 | mock_handler->set_connection_based(true); |
| 4391 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4392 | HttpAuth::AUTH_SERVER); |
| 4393 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4394 | |
| 4395 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4396 | |
| 4397 | MockWrite data_writes1[] = { |
| 4398 | MockWrite("GET / HTTP/1.1\r\n" |
| 4399 | "Host: www.example.org\r\n" |
| 4400 | "Connection: keep-alive\r\n\r\n"), |
| 4401 | }; |
| 4402 | |
| 4403 | MockRead data_reads1[] = { |
| 4404 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4405 | "WWW-Authenticate: Mock\r\n" |
| 4406 | "Connection: keep-alive\r\n\r\n"), |
| 4407 | }; |
| 4408 | |
| 4409 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4410 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4411 | // transaction procceds without an authorization header. |
| 4412 | MockWrite data_writes2[] = { |
| 4413 | MockWrite("GET / HTTP/1.1\r\n" |
| 4414 | "Host: www.example.org\r\n" |
| 4415 | "Connection: keep-alive\r\n\r\n"), |
| 4416 | }; |
| 4417 | |
| 4418 | MockRead data_reads2[] = { |
| 4419 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4420 | "WWW-Authenticate: Mock\r\n" |
| 4421 | "Connection: keep-alive\r\n\r\n"), |
| 4422 | }; |
| 4423 | |
| 4424 | MockWrite data_writes3[] = { |
| 4425 | MockWrite("GET / HTTP/1.1\r\n" |
| 4426 | "Host: www.example.org\r\n" |
| 4427 | "Connection: keep-alive\r\n" |
| 4428 | "Authorization: auth_token\r\n\r\n"), |
| 4429 | }; |
| 4430 | |
| 4431 | MockRead data_reads3[] = { |
| 4432 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4433 | "Content-Length: 5\r\n" |
| 4434 | "Content-Type: text/plain\r\n" |
| 4435 | "Connection: keep-alive\r\n\r\n" |
| 4436 | "Hello"), |
| 4437 | }; |
| 4438 | |
| 4439 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4440 | data_writes1, arraysize(data_writes1)); |
| 4441 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4442 | |
| 4443 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4444 | data_writes2, arraysize(data_writes2)); |
| 4445 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4446 | |
| 4447 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4448 | data_writes3, arraysize(data_writes3)); |
| 4449 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4450 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4451 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4452 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4453 | |
| 4454 | TestCompletionCallback callback; |
| 4455 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4456 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4457 | |
| 4458 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4459 | ASSERT_TRUE(response); |
| 4460 | ASSERT_TRUE(response->headers); |
| 4461 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4462 | |
| 4463 | // The following three tests assert that an authentication challenge was |
| 4464 | // received and that the stack is ready to respond to the challenge using |
| 4465 | // ambient credentials. |
| 4466 | EXPECT_EQ(401, response->headers->response_code()); |
| 4467 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4468 | EXPECT_FALSE(response->auth_challenge); |
| 4469 | |
| 4470 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4471 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4472 | response = trans->GetResponseInfo(); |
| 4473 | ASSERT_TRUE(response); |
| 4474 | ASSERT_TRUE(response->headers); |
| 4475 | |
| 4476 | // The following three tests assert that an authentication challenge was |
| 4477 | // received and that the stack needs explicit credentials before it is ready |
| 4478 | // to respond to the challenge. |
| 4479 | EXPECT_EQ(401, response->headers->response_code()); |
| 4480 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4481 | EXPECT_TRUE(response->auth_challenge); |
| 4482 | |
| 4483 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4484 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4485 | response = trans->GetResponseInfo(); |
| 4486 | ASSERT_TRUE(response); |
| 4487 | ASSERT_TRUE(response->headers); |
| 4488 | EXPECT_EQ(200, response->headers->response_code()); |
| 4489 | |
| 4490 | trans.reset(); |
| 4491 | session->CloseAllConnections(); |
| 4492 | } |
| 4493 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4494 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4495 | // schemes, based on the path of the URL being requests. |
| 4496 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4497 | public: |
| 4498 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4499 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4500 | |
| 4501 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4502 | |
| 4503 | static HostPortPair ProxyHostPortPair() { |
| 4504 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4505 | } |
| 4506 | |
| 4507 | // ProxyResolver implementation. |
| 4508 | int GetProxyForURL(const GURL& url, |
| 4509 | ProxyInfo* results, |
| 4510 | const CompletionCallback& callback, |
| 4511 | std::unique_ptr<Request>* request, |
| 4512 | const NetLogWithSource& /*net_log*/) override { |
| 4513 | *results = ProxyInfo(); |
| 4514 | if (url.path() == "/socks4") { |
| 4515 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4516 | return OK; |
| 4517 | } |
| 4518 | if (url.path() == "/socks5") { |
| 4519 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4520 | return OK; |
| 4521 | } |
| 4522 | if (url.path() == "/http") { |
| 4523 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4524 | return OK; |
| 4525 | } |
| 4526 | if (url.path() == "/https") { |
| 4527 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4528 | return OK; |
| 4529 | } |
| 4530 | NOTREACHED(); |
| 4531 | return ERR_NOT_IMPLEMENTED; |
| 4532 | } |
| 4533 | |
| 4534 | private: |
| 4535 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4536 | }; |
| 4537 | |
| 4538 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4539 | : public ProxyResolverFactory { |
| 4540 | public: |
| 4541 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4542 | : ProxyResolverFactory(false) {} |
| 4543 | |
| 4544 | int CreateProxyResolver( |
| 4545 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 4546 | std::unique_ptr<ProxyResolver>* resolver, |
| 4547 | const CompletionCallback& callback, |
| 4548 | std::unique_ptr<Request>* request) override { |
| 4549 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4550 | return OK; |
| 4551 | } |
| 4552 | |
| 4553 | private: |
| 4554 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4555 | }; |
| 4556 | |
| 4557 | // Check that when different proxy schemes are all applied to a proxy at the |
| 4558 | // same address, the sonnections are not grouped together. i.e., a request to |
| 4559 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4560 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4561 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
| 4562 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 4563 | std::make_unique<ProxyConfigServiceFixed>( |
| 4564 | ProxyConfig::CreateAutoDetect()), |
| 4565 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4566 | nullptr); |
| 4567 | |
| 4568 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4569 | |
| 4570 | MockWrite socks_writes[] = { |
| 4571 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4572 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4573 | MockWrite(SYNCHRONOUS, |
| 4574 | "GET /socks4 HTTP/1.1\r\n" |
| 4575 | "Host: test\r\n" |
| 4576 | "Connection: keep-alive\r\n\r\n"), |
| 4577 | }; |
| 4578 | MockRead socks_reads[] = { |
| 4579 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4580 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4581 | "Connection: keep-alive\r\n" |
| 4582 | "Content-Length: 15\r\n\r\n" |
| 4583 | "SOCKS4 Response"), |
| 4584 | }; |
| 4585 | StaticSocketDataProvider socks_data(socks_reads, arraysize(socks_reads), |
| 4586 | socks_writes, arraysize(socks_writes)); |
| 4587 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4588 | |
| 4589 | const char kSOCKS5Request[] = { |
| 4590 | 0x05, // Version |
| 4591 | 0x01, // Command (CONNECT) |
| 4592 | 0x00, // Reserved |
| 4593 | 0x03, // Address type (DOMAINNAME) |
| 4594 | 0x04, // Length of domain (4) |
| 4595 | 't', 'e', 's', 't', // Domain string |
| 4596 | 0x00, 0x50, // 16-bit port (80) |
| 4597 | }; |
| 4598 | MockWrite socks5_writes[] = { |
| 4599 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
| 4600 | MockWrite(ASYNC, kSOCKS5Request, arraysize(kSOCKS5Request)), |
| 4601 | MockWrite(SYNCHRONOUS, |
| 4602 | "GET /socks5 HTTP/1.1\r\n" |
| 4603 | "Host: test\r\n" |
| 4604 | "Connection: keep-alive\r\n\r\n"), |
| 4605 | }; |
| 4606 | MockRead socks5_reads[] = { |
| 4607 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4608 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4609 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4610 | "Connection: keep-alive\r\n" |
| 4611 | "Content-Length: 15\r\n\r\n" |
| 4612 | "SOCKS5 Response"), |
| 4613 | }; |
| 4614 | StaticSocketDataProvider socks5_data(socks5_reads, arraysize(socks5_reads), |
| 4615 | socks5_writes, arraysize(socks5_writes)); |
| 4616 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 4617 | |
| 4618 | MockWrite http_writes[] = { |
| 4619 | MockWrite(SYNCHRONOUS, |
| 4620 | "GET http://test/http HTTP/1.1\r\n" |
| 4621 | "Host: test\r\n" |
| 4622 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4623 | }; |
| 4624 | MockRead http_reads[] = { |
| 4625 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4626 | "Proxy-Connection: keep-alive\r\n" |
| 4627 | "Content-Length: 13\r\n\r\n" |
| 4628 | "HTTP Response"), |
| 4629 | }; |
| 4630 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 4631 | http_writes, arraysize(http_writes)); |
| 4632 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 4633 | |
| 4634 | MockWrite https_writes[] = { |
| 4635 | MockWrite(SYNCHRONOUS, |
| 4636 | "GET http://test/https HTTP/1.1\r\n" |
| 4637 | "Host: test\r\n" |
| 4638 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4639 | }; |
| 4640 | MockRead https_reads[] = { |
| 4641 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4642 | "Proxy-Connection: keep-alive\r\n" |
| 4643 | "Content-Length: 14\r\n\r\n" |
| 4644 | "HTTPS Response"), |
| 4645 | }; |
| 4646 | StaticSocketDataProvider https_data(https_reads, arraysize(https_reads), |
| 4647 | https_writes, arraysize(https_writes)); |
| 4648 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 4649 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 4650 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4651 | |
| 4652 | struct TestCase { |
| 4653 | GURL url; |
| 4654 | std::string expected_response; |
| 4655 | // How many idle sockets there should be in the SOCKS proxy socket pool |
| 4656 | // after the test. |
| 4657 | int expected_idle_socks_sockets; |
| 4658 | // How many idle sockets there should be in the HTTP proxy socket pool after |
| 4659 | // the test. |
| 4660 | int expected_idle_http_sockets; |
| 4661 | } const kTestCases[] = { |
| 4662 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0}, |
| 4663 | {GURL("http://test/socks5"), "SOCKS5 Response", 2, 0}, |
| 4664 | {GURL("http://test/http"), "HTTP Response", 2, 1}, |
| 4665 | {GURL("http://test/https"), "HTTPS Response", 2, 2}, |
| 4666 | }; |
| 4667 | |
| 4668 | for (const auto& test_case : kTestCases) { |
| 4669 | HttpRequestInfo request; |
| 4670 | request.method = "GET"; |
| 4671 | request.url = test_case.url; |
| 4672 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 4673 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 4674 | session.get()); |
| 4675 | TestCompletionCallback callback; |
| 4676 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4677 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4678 | |
| 4679 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4680 | ASSERT_TRUE(response); |
| 4681 | ASSERT_TRUE(response->headers); |
| 4682 | EXPECT_EQ(200, response->headers->response_code()); |
| 4683 | std::string response_data; |
| 4684 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4685 | EXPECT_EQ(test_case.expected_response, response_data); |
| 4686 | |
| 4687 | // Return the socket to the socket pool, so can make sure it's not used for |
| 4688 | // the next requests. |
| 4689 | trans.reset(); |
| 4690 | base::RunLoop().RunUntilIdle(); |
| 4691 | |
| 4692 | // Check the number of idle sockets in the pool, to make sure that used |
| 4693 | // sockets are indeed being returned to the socket pool. If each request |
| 4694 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 4695 | // pass. |
| 4696 | EXPECT_EQ( |
| 4697 | test_case.expected_idle_socks_sockets, |
| 4698 | session |
| 4699 | ->GetSocketPoolForSOCKSProxy( |
| 4700 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4701 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4702 | ->IdleSocketCount()); |
| 4703 | EXPECT_EQ( |
| 4704 | test_case.expected_idle_http_sockets, |
| 4705 | session |
| 4706 | ->GetSocketPoolForHTTPProxy( |
| 4707 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4708 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4709 | ->IdleSocketCount()); |
| 4710 | } |
| 4711 | } |
| 4712 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4713 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4714 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4715 | HttpRequestInfo request1; |
| 4716 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4717 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4718 | |
| 4719 | HttpRequestInfo request2; |
| 4720 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4721 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4722 | |
| 4723 | // Configure against proxy server "myproxy:70". |
brettw | c1213d9 | 2016-11-12 03:41:13 | [diff] [blame] | 4724 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4725 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4726 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4728 | |
| 4729 | // Since we have proxy, should try to establish tunnel. |
| 4730 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4731 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4732 | "Host: www.example.org:443\r\n" |
| 4733 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4734 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4735 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4736 | "Host: www.example.org\r\n" |
| 4737 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4738 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4739 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4740 | "Host: www.example.org\r\n" |
| 4741 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4742 | }; |
| 4743 | |
| 4744 | // The proxy responds to the connect with a 407, using a persistent |
| 4745 | // connection. |
| 4746 | MockRead data_reads1[] = { |
| 4747 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4748 | |
| 4749 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4750 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4751 | MockRead(SYNCHRONOUS, "1"), |
| 4752 | |
| 4753 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4754 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4755 | MockRead(SYNCHRONOUS, "22"), |
| 4756 | }; |
| 4757 | |
| 4758 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4759 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4760 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4761 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4762 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4763 | |
| 4764 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4765 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4766 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4767 | |
| 4768 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4769 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4770 | |
| 4771 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4772 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4773 | |
| 4774 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4775 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4776 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4777 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4778 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4779 | |
| 4780 | LoadTimingInfo load_timing_info1; |
| 4781 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4782 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4783 | |
| 4784 | trans1.reset(); |
| 4785 | |
| 4786 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4787 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4788 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4789 | |
| 4790 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4791 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4792 | |
| 4793 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4794 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4795 | |
| 4796 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4797 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4798 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4799 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4800 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4801 | |
| 4802 | LoadTimingInfo load_timing_info2; |
| 4803 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4804 | TestLoadTimingReused(load_timing_info2); |
| 4805 | |
| 4806 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4807 | |
| 4808 | trans2.reset(); |
| 4809 | session->CloseAllConnections(); |
| 4810 | } |
| 4811 | |
| 4812 | // 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] | 4813 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4814 | HttpRequestInfo request1; |
| 4815 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4816 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4817 | |
| 4818 | HttpRequestInfo request2; |
| 4819 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4820 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4821 | |
| 4822 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4823 | session_deps_.proxy_service = |
| 4824 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4825 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4826 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4828 | |
| 4829 | // Since we have proxy, should try to establish tunnel. |
| 4830 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4831 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4832 | "Host: www.example.org:443\r\n" |
| 4833 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4834 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4835 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4836 | "Host: www.example.org\r\n" |
| 4837 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4838 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4839 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4840 | "Host: www.example.org\r\n" |
| 4841 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4842 | }; |
| 4843 | |
| 4844 | // The proxy responds to the connect with a 407, using a persistent |
| 4845 | // connection. |
| 4846 | MockRead data_reads1[] = { |
| 4847 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4848 | |
| 4849 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4850 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4851 | MockRead(SYNCHRONOUS, "1"), |
| 4852 | |
| 4853 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4854 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4855 | MockRead(SYNCHRONOUS, "22"), |
| 4856 | }; |
| 4857 | |
| 4858 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4859 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4860 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4861 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4863 | |
| 4864 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4865 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4866 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4867 | |
| 4868 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4869 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4870 | |
| 4871 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4872 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4873 | |
| 4874 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4875 | ASSERT_TRUE(response1); |
| 4876 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4877 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4878 | |
| 4879 | LoadTimingInfo load_timing_info1; |
| 4880 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4881 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4882 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4883 | |
| 4884 | trans1.reset(); |
| 4885 | |
| 4886 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4887 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4888 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4889 | |
| 4890 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4891 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4892 | |
| 4893 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4894 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4895 | |
| 4896 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4897 | ASSERT_TRUE(response2); |
| 4898 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4899 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4900 | |
| 4901 | LoadTimingInfo load_timing_info2; |
| 4902 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4903 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4904 | |
| 4905 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4906 | |
| 4907 | trans2.reset(); |
| 4908 | session->CloseAllConnections(); |
| 4909 | } |
| 4910 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4911 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4912 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4913 | HttpRequestInfo request; |
| 4914 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4915 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4916 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4917 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4918 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4919 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4920 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4921 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4922 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4923 | // Since we have proxy, should use full url |
| 4924 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4925 | MockWrite( |
| 4926 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4927 | "Host: www.example.org\r\n" |
| 4928 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4929 | }; |
| 4930 | |
| 4931 | MockRead data_reads1[] = { |
| 4932 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4933 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4934 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4935 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4936 | }; |
| 4937 | |
| 4938 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4939 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4940 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4941 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4942 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4943 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4944 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4945 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4946 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4947 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4948 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4949 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4950 | |
| 4951 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4952 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4953 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4954 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4955 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4956 | TestLoadTimingNotReused(load_timing_info, |
| 4957 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4958 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4959 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4960 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4961 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4962 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4963 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4964 | EXPECT_EQ(200, response->headers->response_code()); |
| 4965 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4966 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4967 | |
| 4968 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4969 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4970 | } |
| 4971 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4972 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4973 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4974 | HttpRequestInfo request; |
| 4975 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4976 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4977 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4978 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4979 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4980 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4981 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4982 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4983 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4984 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4985 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4986 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4987 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4988 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4989 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4990 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4991 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4992 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4993 | }; |
| 4994 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4995 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4996 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4997 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4998 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4999 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5000 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5001 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5002 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5003 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5004 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5005 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5006 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5007 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5008 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5009 | |
| 5010 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5011 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5012 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5013 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5014 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5015 | TestLoadTimingNotReused(load_timing_info, |
| 5016 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5017 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5018 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5019 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5020 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5021 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5022 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5023 | |
| 5024 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5025 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5026 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5027 | } |
| 5028 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5029 | // Verifies that a session which races and wins against the owning transaction |
| 5030 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5031 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5032 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5033 | HttpRequestInfo request; |
| 5034 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5035 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5036 | |
| 5037 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5038 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5039 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5040 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5041 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5042 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5043 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5044 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5045 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5046 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5047 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5048 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5049 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5050 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5051 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5052 | }; |
| 5053 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5054 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5055 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5056 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5057 | |
| 5058 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5059 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5060 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5061 | |
| 5062 | TestCompletionCallback callback1; |
| 5063 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5064 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5065 | |
| 5066 | // Stall the hostname resolution begun by the transaction. |
| 5067 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 5068 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5069 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5070 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5071 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5072 | |
| 5073 | // Race a session to the proxy, which completes first. |
| 5074 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5075 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
| 5076 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5077 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5078 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5079 | |
| 5080 | // Unstall the resolution begun by the transaction. |
| 5081 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5082 | session_deps_.host_resolver->ResolveAllPending(); |
| 5083 | |
| 5084 | EXPECT_FALSE(callback1.have_result()); |
| 5085 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5086 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5087 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5088 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5089 | ASSERT_TRUE(response); |
| 5090 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5091 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5092 | |
| 5093 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5094 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5095 | EXPECT_EQ(kUploadData, response_data); |
| 5096 | } |
| 5097 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5098 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5099 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5100 | HttpRequestInfo request; |
| 5101 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5102 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5103 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5104 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5105 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5106 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5107 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5108 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5109 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5110 | // The first request will be a bare GET, the second request will be a |
| 5111 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5112 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5113 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5114 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5115 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5116 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5117 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5118 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5119 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 5120 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 5121 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5122 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5123 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5124 | }; |
| 5125 | |
| 5126 | // The first response is a 407 proxy authentication challenge, and the second |
| 5127 | // response will be a 200 response since the second request includes a valid |
| 5128 | // Authorization header. |
| 5129 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5130 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5131 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5132 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 5133 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5134 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 5135 | SpdySerializedFrame body_authentication( |
| 5136 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5137 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5138 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5139 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5140 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5141 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5142 | CreateMockRead(resp_data, 4), |
| 5143 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5144 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5145 | }; |
| 5146 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5147 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5148 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5149 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5150 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5151 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5152 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5153 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5154 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5155 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5156 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5157 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5158 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5159 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5160 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5161 | |
| 5162 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5163 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5164 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5165 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5166 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5167 | ASSERT_TRUE(response); |
| 5168 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5169 | EXPECT_EQ(407, response->headers->response_code()); |
| 5170 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5171 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5173 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5174 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5175 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5176 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5177 | |
| 5178 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5179 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5180 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5181 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5182 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5183 | ASSERT_TRUE(response_restart); |
| 5184 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5185 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5186 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5187 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5188 | } |
| 5189 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5190 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5191 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5192 | HttpRequestInfo request; |
| 5193 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5194 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5195 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5196 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5197 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5198 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5199 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5200 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5201 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5202 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5203 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5204 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5205 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5206 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5207 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5208 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5209 | const char get[] = |
| 5210 | "GET / HTTP/1.1\r\n" |
| 5211 | "Host: www.example.org\r\n" |
| 5212 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5213 | SpdySerializedFrame wrapped_get( |
| 5214 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5215 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5216 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5217 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5218 | SpdySerializedFrame wrapped_get_resp( |
| 5219 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 5220 | SpdySerializedFrame wrapped_body( |
| 5221 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 5222 | SpdySerializedFrame window_update( |
| 5223 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5224 | |
| 5225 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5226 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5227 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5228 | }; |
| 5229 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5230 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5231 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5232 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5233 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5234 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5235 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5236 | }; |
| 5237 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5238 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5239 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5240 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5241 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5242 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5243 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5244 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5245 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5246 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5248 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5249 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5250 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5251 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5252 | |
| 5253 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5254 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5255 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5256 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5257 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5258 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5259 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5260 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5261 | ASSERT_TRUE(response); |
| 5262 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5263 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5264 | |
| 5265 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5266 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5267 | EXPECT_EQ("1234567890", response_data); |
| 5268 | } |
| 5269 | |
| 5270 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5271 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5272 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5273 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5274 | HttpRequestInfo request; |
| 5275 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5276 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5277 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5278 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5279 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5280 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5281 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5282 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5283 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5284 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5285 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5286 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5287 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5288 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5289 | // fetch https://www.example.org/ via SPDY |
| 5290 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5291 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5292 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5293 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5294 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5295 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5296 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5297 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5298 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5299 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5300 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5301 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5302 | SpdySerializedFrame window_update_get_resp( |
| 5303 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 5304 | SpdySerializedFrame window_update_body( |
| 5305 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5306 | |
| 5307 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5308 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5309 | CreateMockWrite(window_update_get_resp, 6), |
| 5310 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5311 | }; |
| 5312 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5313 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5314 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5315 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5316 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5317 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5318 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5319 | }; |
| 5320 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5321 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5322 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5323 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5324 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5325 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5326 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5327 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5328 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5329 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5330 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5331 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5332 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5333 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5334 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5335 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5336 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5337 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5338 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5339 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5340 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5341 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5342 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5343 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5344 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5345 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5346 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5347 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5348 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5349 | ASSERT_TRUE(response); |
| 5350 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5351 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5352 | |
| 5353 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5354 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5355 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5359 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5360 | HttpRequestInfo request; |
| 5361 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5362 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5363 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5364 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5365 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5366 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5367 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5368 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5369 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5370 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5371 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5372 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5373 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5374 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5375 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5376 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5377 | |
| 5378 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5379 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5380 | }; |
| 5381 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5382 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5383 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5384 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5385 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5386 | }; |
| 5387 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5388 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5389 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5390 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5391 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5392 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5393 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5394 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5395 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5396 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5397 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5398 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5399 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5400 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5401 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5402 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5403 | |
| 5404 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5405 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5406 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5407 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5408 | } |
| 5409 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5410 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5411 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5412 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5413 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5414 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5415 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5416 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5417 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5418 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5419 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5420 | |
| 5421 | HttpRequestInfo request1; |
| 5422 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5423 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5424 | request1.load_flags = 0; |
| 5425 | |
| 5426 | HttpRequestInfo request2; |
| 5427 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5428 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5429 | request2.load_flags = 0; |
| 5430 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5431 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5432 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5433 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5434 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5435 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5436 | // Fetch https://www.example.org/ via HTTP. |
| 5437 | const char get1[] = |
| 5438 | "GET / HTTP/1.1\r\n" |
| 5439 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5440 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5441 | SpdySerializedFrame wrapped_get1( |
| 5442 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5443 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5444 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5445 | SpdySerializedFrame wrapped_get_resp1( |
| 5446 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5447 | SpdySerializedFrame wrapped_body1( |
| 5448 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5449 | SpdySerializedFrame window_update( |
| 5450 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5451 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5452 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5453 | SpdyHeaderBlock connect2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 5454 | connect2_block[kHttp2MethodHeader] = "CONNECT"; |
| 5455 | connect2_block[kHttp2AuthorityHeader] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5456 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5457 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5458 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5459 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5460 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5461 | // Fetch https://mail.example.org/ via HTTP. |
| 5462 | const char get2[] = |
| 5463 | "GET / HTTP/1.1\r\n" |
| 5464 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5465 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5466 | SpdySerializedFrame wrapped_get2( |
| 5467 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5468 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5469 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5470 | SpdySerializedFrame wrapped_get_resp2( |
| 5471 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5472 | SpdySerializedFrame wrapped_body2( |
| 5473 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5474 | |
| 5475 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5476 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5477 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5478 | }; |
| 5479 | |
| 5480 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5481 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5482 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5483 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5484 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5485 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5486 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5487 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5488 | }; |
| 5489 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5490 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5491 | arraysize(spdy_writes)); |
| 5492 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5493 | |
| 5494 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5495 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5496 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5497 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5498 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5499 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5500 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5501 | |
| 5502 | TestCompletionCallback callback; |
| 5503 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5504 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5505 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5506 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5507 | |
| 5508 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5509 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5510 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5511 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5512 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5513 | ASSERT_TRUE(response); |
| 5514 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5515 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5516 | |
| 5517 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5518 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5519 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5520 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5521 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5522 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5523 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5524 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5525 | |
| 5526 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5527 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5528 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5529 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5530 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5531 | |
| 5532 | // The requests should have different IDs, since they each are using their own |
| 5533 | // separate stream. |
| 5534 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5535 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5536 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5537 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5538 | } |
| 5539 | |
| 5540 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5541 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5542 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5543 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5544 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5545 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5546 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5547 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5548 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5549 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5550 | |
| 5551 | HttpRequestInfo request1; |
| 5552 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5553 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5554 | request1.load_flags = 0; |
| 5555 | |
| 5556 | HttpRequestInfo request2; |
| 5557 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5558 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5559 | request2.load_flags = 0; |
| 5560 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5561 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5562 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5563 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5564 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5565 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5566 | // Fetch https://www.example.org/ via HTTP. |
| 5567 | const char get1[] = |
| 5568 | "GET / HTTP/1.1\r\n" |
| 5569 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5570 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5571 | SpdySerializedFrame wrapped_get1( |
| 5572 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5573 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5574 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5575 | SpdySerializedFrame wrapped_get_resp1( |
| 5576 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5577 | SpdySerializedFrame wrapped_body1( |
| 5578 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5579 | SpdySerializedFrame window_update( |
| 5580 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[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/2 via HTTP. |
| 5583 | const char get2[] = |
| 5584 | "GET /2 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_get2( |
| 5588 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5589 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5590 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5591 | SpdySerializedFrame wrapped_get_resp2( |
| 5592 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5593 | SpdySerializedFrame wrapped_body2( |
| 5594 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5595 | |
| 5596 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5597 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5598 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5599 | }; |
| 5600 | |
| 5601 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5602 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5603 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5604 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5605 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5606 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5607 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5608 | }; |
| 5609 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5610 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5611 | arraysize(spdy_writes)); |
| 5612 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5613 | |
| 5614 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5615 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5616 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5617 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5618 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5619 | |
| 5620 | TestCompletionCallback callback; |
| 5621 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5622 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5623 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5624 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5625 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5626 | |
| 5627 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5628 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5629 | |
| 5630 | LoadTimingInfo load_timing_info; |
| 5631 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5632 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5633 | |
| 5634 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5635 | ASSERT_TRUE(response); |
| 5636 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5637 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5638 | |
| 5639 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5640 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5641 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5642 | trans.reset(); |
| 5643 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5644 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5645 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5646 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5648 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5649 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5650 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5651 | |
| 5652 | LoadTimingInfo load_timing_info2; |
| 5653 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5654 | TestLoadTimingReused(load_timing_info2); |
| 5655 | |
| 5656 | // The requests should have the same ID. |
| 5657 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5658 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5659 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5660 | } |
| 5661 | |
| 5662 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5663 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5664 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5665 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5666 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5667 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5668 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5669 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5670 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5671 | |
| 5672 | HttpRequestInfo request1; |
| 5673 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5674 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5675 | request1.load_flags = 0; |
| 5676 | |
| 5677 | HttpRequestInfo request2; |
| 5678 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5679 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5680 | request2.load_flags = 0; |
| 5681 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5682 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5683 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5684 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5685 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5686 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5687 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5688 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5689 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5690 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5691 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5692 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5693 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5694 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5695 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5696 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5697 | SpdySerializedFrame body2( |
| 5698 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5699 | |
| 5700 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5701 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5702 | }; |
| 5703 | |
| 5704 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5705 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5706 | CreateMockRead(body1, 2, ASYNC), |
| 5707 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5708 | CreateMockRead(body2, 5, ASYNC), |
| 5709 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5710 | }; |
| 5711 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5712 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5713 | arraysize(spdy_writes)); |
| 5714 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5715 | |
| 5716 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5717 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5718 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5719 | |
| 5720 | TestCompletionCallback callback; |
| 5721 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5722 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5723 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5724 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5725 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5726 | |
| 5727 | LoadTimingInfo load_timing_info; |
| 5728 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5729 | TestLoadTimingNotReused(load_timing_info, |
| 5730 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5731 | |
| 5732 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5733 | ASSERT_TRUE(response); |
| 5734 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5735 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5736 | |
| 5737 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5738 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5739 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5740 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5741 | // Delete the first request, so the second one can reuse the socket. |
| 5742 | trans.reset(); |
| 5743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5744 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5745 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5746 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5747 | |
| 5748 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5749 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5750 | TestLoadTimingReused(load_timing_info2); |
| 5751 | |
| 5752 | // The requests should have the same ID. |
| 5753 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5755 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5756 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5757 | } |
| 5758 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5759 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5760 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5761 | HttpRequestInfo request; |
| 5762 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5763 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5764 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5765 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5766 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5767 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5768 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5769 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5770 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5771 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5772 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5773 | // Since we have proxy, should use full url |
| 5774 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5775 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5776 | "Host: www.example.org\r\n" |
| 5777 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5778 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5779 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5780 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5781 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5782 | "Host: www.example.org\r\n" |
| 5783 | "Proxy-Connection: keep-alive\r\n" |
| 5784 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5785 | }; |
| 5786 | |
| 5787 | // The proxy responds to the GET with a 407, using a persistent |
| 5788 | // connection. |
| 5789 | MockRead data_reads1[] = { |
| 5790 | // No credentials. |
| 5791 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5792 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5793 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5794 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5795 | |
| 5796 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5797 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5798 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5799 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5800 | }; |
| 5801 | |
| 5802 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5803 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5804 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5805 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5806 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5808 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5810 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5811 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5812 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5814 | |
| 5815 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5816 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5817 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5818 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5819 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5820 | TestLoadTimingNotReused(load_timing_info, |
| 5821 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5823 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5824 | ASSERT_TRUE(response); |
| 5825 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5826 | EXPECT_EQ(407, response->headers->response_code()); |
| 5827 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5828 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5830 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5832 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5833 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5834 | |
| 5835 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5836 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5837 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5838 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5839 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5840 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5841 | TestLoadTimingReused(load_timing_info); |
| 5842 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5843 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5844 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5845 | |
| 5846 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5847 | EXPECT_EQ(200, response->headers->response_code()); |
| 5848 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5849 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5850 | |
| 5851 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5852 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5853 | } |
| 5854 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5855 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5856 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5857 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5858 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5859 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5860 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5861 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5862 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5863 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5864 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5865 | // Since we have proxy, should try to establish tunnel. |
| 5866 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5867 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5868 | "Host: www.example.org:443\r\n" |
| 5869 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5870 | }; |
| 5871 | |
| 5872 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5873 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5874 | // No response body because the test stops reading here. |
| 5875 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5876 | }; |
| 5877 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5878 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5879 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5880 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5881 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5882 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5883 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5884 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5885 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5886 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5887 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5888 | |
| 5889 | rv = callback.WaitForResult(); |
| 5890 | EXPECT_EQ(expected_status, rv); |
| 5891 | } |
| 5892 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5893 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5894 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5895 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5896 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5897 | } |
| 5898 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5899 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5900 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5901 | } |
| 5902 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5903 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5904 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5905 | } |
| 5906 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5907 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5908 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5909 | } |
| 5910 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5911 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5912 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5913 | } |
| 5914 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5915 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5916 | ConnectStatusHelper( |
| 5917 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5918 | } |
| 5919 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5920 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5921 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5922 | } |
| 5923 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5924 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5925 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5926 | } |
| 5927 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5928 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5929 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5930 | } |
| 5931 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5932 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5933 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5934 | } |
| 5935 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5936 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5937 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5938 | } |
| 5939 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5940 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5941 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5942 | } |
| 5943 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5944 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5945 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5946 | } |
| 5947 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5948 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5949 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5950 | } |
| 5951 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5952 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5953 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5954 | } |
| 5955 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5956 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5957 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5958 | } |
| 5959 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5960 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5961 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5962 | } |
| 5963 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5964 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5965 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5966 | } |
| 5967 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5968 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5969 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5970 | } |
| 5971 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5972 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5973 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5974 | } |
| 5975 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5976 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5977 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5978 | } |
| 5979 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5980 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5981 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5982 | } |
| 5983 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5984 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5985 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5986 | } |
| 5987 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5988 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5989 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5990 | } |
| 5991 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5992 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5993 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5994 | } |
| 5995 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5996 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5997 | ConnectStatusHelperWithExpectedStatus( |
| 5998 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5999 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6000 | } |
| 6001 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6002 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6003 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6004 | } |
| 6005 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6006 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6007 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6008 | } |
| 6009 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6010 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6011 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6012 | } |
| 6013 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6014 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6015 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6016 | } |
| 6017 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6018 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6019 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6020 | } |
| 6021 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6022 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6023 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6024 | } |
| 6025 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6026 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6027 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6028 | } |
| 6029 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6030 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6031 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6032 | } |
| 6033 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6034 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6035 | ConnectStatusHelper( |
| 6036 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6037 | } |
| 6038 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6039 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6040 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6041 | } |
| 6042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6043 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6044 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6045 | } |
| 6046 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6047 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6048 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6049 | } |
| 6050 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6051 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6052 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6053 | } |
| 6054 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6055 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6056 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6057 | } |
| 6058 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6059 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6060 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6061 | } |
| 6062 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6063 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6064 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6065 | } |
| 6066 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6067 | // Test the flow when both the proxy server AND origin server require |
| 6068 | // authentication. Again, this uses basic auth for both since that is |
| 6069 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6070 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6071 | HttpRequestInfo request; |
| 6072 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6073 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6074 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6075 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6076 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6077 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6078 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6079 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6080 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6081 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6082 | MockWrite( |
| 6083 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6084 | "Host: www.example.org\r\n" |
| 6085 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6086 | }; |
| 6087 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6088 | MockRead data_reads1[] = { |
| 6089 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6090 | // Give a couple authenticate options (only the middle one is actually |
| 6091 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6092 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6093 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6094 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6095 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6096 | // Large content-length -- won't matter, as connection will be reset. |
| 6097 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6098 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6099 | }; |
| 6100 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6101 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6102 | // request we should be issuing -- the final header line contains the |
| 6103 | // proxy's credentials. |
| 6104 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6105 | MockWrite( |
| 6106 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6107 | "Host: www.example.org\r\n" |
| 6108 | "Proxy-Connection: keep-alive\r\n" |
| 6109 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6110 | }; |
| 6111 | |
| 6112 | // Now the proxy server lets the request pass through to origin server. |
| 6113 | // The origin server responds with a 401. |
| 6114 | MockRead data_reads2[] = { |
| 6115 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6116 | // Note: We are using the same realm-name as the proxy server. This is |
| 6117 | // completely valid, as realms are unique across hosts. |
| 6118 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6119 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6120 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6121 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6122 | }; |
| 6123 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6124 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6125 | // the credentials for both the proxy and origin server. |
| 6126 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6127 | MockWrite( |
| 6128 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6129 | "Host: www.example.org\r\n" |
| 6130 | "Proxy-Connection: keep-alive\r\n" |
| 6131 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 6132 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6133 | }; |
| 6134 | |
| 6135 | // Lastly we get the desired content. |
| 6136 | MockRead data_reads3[] = { |
| 6137 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6138 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6139 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6140 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6141 | }; |
| 6142 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6143 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6144 | data_writes1, arraysize(data_writes1)); |
| 6145 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6146 | data_writes2, arraysize(data_writes2)); |
| 6147 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6148 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6149 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6150 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6151 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6152 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6153 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6154 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6155 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6156 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6157 | |
| 6158 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6159 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6161 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6162 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6163 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6165 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6166 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6167 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6168 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6169 | |
| 6170 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6171 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6172 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6173 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6174 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6175 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6176 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6177 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6178 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6179 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 6180 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6181 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6182 | |
| 6183 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6184 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6186 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6187 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6188 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6189 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6190 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6191 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 6192 | // can't hook into its internals to cause it to generate predictable NTLM |
| 6193 | // authorization headers. |
| 6194 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6195 | // The NTLM authentication unit tests are based on known test data from the |
| 6196 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 6197 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 6198 | // for the implementation and testing of the protocol. |
| 6199 | // |
| 6200 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6201 | |
| 6202 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6203 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6204 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6205 | request.method = "GET"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6206 | request.url = GURL("https://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6207 | |
| 6208 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6209 | // to other auth schemes. |
| 6210 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6211 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6212 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6213 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6214 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6215 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6216 | // Generate the NTLM messages based on known test data. |
| 6217 | std::string negotiate_msg; |
| 6218 | std::string challenge_msg; |
| 6219 | std::string authenticate_msg; |
| 6220 | base::Base64Encode( |
| 6221 | base::StringPiece( |
| 6222 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6223 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6224 | &negotiate_msg); |
| 6225 | base::Base64Encode(base::StringPiece(reinterpret_cast<const char*>( |
| 6226 | ntlm::test::kChallengeMsgV1), |
| 6227 | arraysize(ntlm::test::kChallengeMsgV1)), |
| 6228 | &challenge_msg); |
| 6229 | base::Base64Encode( |
| 6230 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6231 | reinterpret_cast<const char*>( |
| 6232 | ntlm::test::kExpectedAuthenticateMsgSpecResponseV1), |
| 6233 | arraysize(ntlm::test::kExpectedAuthenticateMsgSpecResponseV1)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6234 | &authenticate_msg); |
| 6235 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6236 | MockWrite data_writes1[] = { |
| 6237 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6238 | "Host: 172.22.68.17\r\n" |
| 6239 | "Connection: keep-alive\r\n\r\n"), |
| 6240 | }; |
| 6241 | |
| 6242 | MockRead data_reads1[] = { |
| 6243 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6244 | // Negotiate and NTLM are often requested together. However, we only want |
| 6245 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6246 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6247 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6248 | MockRead("Connection: close\r\n"), |
| 6249 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6250 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6251 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6252 | }; |
| 6253 | |
| 6254 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6255 | // After restarting with a null identity, this is the |
| 6256 | // request we should be issuing -- the final header line contains a Type |
| 6257 | // 1 message. |
| 6258 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6259 | "Host: 172.22.68.17\r\n" |
| 6260 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6261 | "Authorization: NTLM "), |
| 6262 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6263 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6264 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6265 | // (using correct credentials). The second request continues on the |
| 6266 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6267 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6268 | "Host: 172.22.68.17\r\n" |
| 6269 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6270 | "Authorization: NTLM "), |
| 6271 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6272 | }; |
| 6273 | |
| 6274 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6275 | // The origin server responds with a Type 2 message. |
| 6276 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6277 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6278 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6279 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6280 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6281 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6282 | // Lastly we get the desired content. |
| 6283 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6284 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6285 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6286 | }; |
| 6287 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6288 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6289 | data_writes1, arraysize(data_writes1)); |
| 6290 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6291 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6292 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6293 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6294 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6295 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6296 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6297 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6298 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6299 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6300 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6301 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6302 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6303 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6304 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6305 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6306 | |
| 6307 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6308 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6309 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6310 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6311 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6312 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6313 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6314 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6315 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6316 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6317 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6318 | rv = trans.RestartWithAuth( |
| 6319 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6320 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6321 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6322 | |
| 6323 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6324 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6325 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6326 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6327 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6328 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6329 | ASSERT_TRUE(response); |
| 6330 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6331 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6332 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6333 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6334 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6335 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6336 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6337 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6338 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6339 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6340 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6341 | ASSERT_TRUE(response); |
| 6342 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6343 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6344 | |
| 6345 | std::string response_data; |
| 6346 | rv = ReadTransaction(&trans, &response_data); |
| 6347 | EXPECT_THAT(rv, IsOk()); |
| 6348 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6349 | |
| 6350 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6351 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6352 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6353 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6354 | } |
| 6355 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6356 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6357 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV1WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6358 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6359 | request.method = "GET"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6360 | request.url = GURL("https://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6361 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6362 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6363 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6364 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6365 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6366 | // Generate the NTLM messages based on known test data. |
| 6367 | std::string negotiate_msg; |
| 6368 | std::string challenge_msg; |
| 6369 | std::string authenticate_msg; |
| 6370 | base::Base64Encode( |
| 6371 | base::StringPiece( |
| 6372 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6373 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6374 | &negotiate_msg); |
| 6375 | base::Base64Encode(base::StringPiece(reinterpret_cast<const char*>( |
| 6376 | ntlm::test::kChallengeMsgV1), |
| 6377 | arraysize(ntlm::test::kChallengeMsgV1)), |
| 6378 | &challenge_msg); |
| 6379 | base::Base64Encode( |
| 6380 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6381 | reinterpret_cast<const char*>( |
| 6382 | ntlm::test::kExpectedAuthenticateMsgSpecResponseV1), |
| 6383 | arraysize(ntlm::test::kExpectedAuthenticateMsgSpecResponseV1)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6384 | &authenticate_msg); |
| 6385 | |
| 6386 | // The authenticate message when |kWrongPassword| is sent. |
| 6387 | std::string wrong_password_authenticate_msg( |
| 6388 | "TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAAwADABwAAAACAAIAHwAAAAQABAAhAAAAAAA" |
| 6389 | "AABAAAAAA4IIAKqqqqqqqqqqAAAAAAAAAAAAAAAAAAAAAF2npafgDxlql9qxEIhLlsuuJIEd" |
| 6390 | "NQHk7kQAbwBtAGEAaQBuAFUAcwBlAHIAQwBPAE0AUABVAFQARQBSAA=="); |
| 6391 | |
| 6392 | // Sanity check that this is the same as |authenticate_msg| except for the |
| 6393 | // 24 bytes (32 encoded chars) of the NTLM Response. |
| 6394 | ASSERT_EQ(authenticate_msg.length(), |
| 6395 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6396 | ASSERT_EQ(authenticate_msg.length(), 200u); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6397 | ASSERT_EQ(base::StringPiece(authenticate_msg.data(), 117), |
| 6398 | base::StringPiece(wrong_password_authenticate_msg.data(), 117)); |
| 6399 | ASSERT_EQ( |
| 6400 | base::StringPiece(authenticate_msg.data() + 149, 51), |
| 6401 | base::StringPiece(wrong_password_authenticate_msg.data() + 149, 51)); |
| 6402 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6403 | MockWrite data_writes1[] = { |
| 6404 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6405 | "Host: 172.22.68.17\r\n" |
| 6406 | "Connection: keep-alive\r\n\r\n"), |
| 6407 | }; |
| 6408 | |
| 6409 | MockRead data_reads1[] = { |
| 6410 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6411 | // Negotiate and NTLM are often requested together. However, we only want |
| 6412 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6413 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6414 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6415 | MockRead("Connection: close\r\n"), |
| 6416 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6417 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6418 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6419 | }; |
| 6420 | |
| 6421 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6422 | // After restarting with a null identity, this is the |
| 6423 | // request we should be issuing -- the final header line contains a Type |
| 6424 | // 1 message. |
| 6425 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6426 | "Host: 172.22.68.17\r\n" |
| 6427 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6428 | "Authorization: NTLM "), |
| 6429 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6430 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6431 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6432 | // (using incorrect credentials). The second request continues on the |
| 6433 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6434 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6435 | "Host: 172.22.68.17\r\n" |
| 6436 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6437 | "Authorization: NTLM "), |
| 6438 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6439 | }; |
| 6440 | |
| 6441 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6442 | // The origin server responds with a Type 2 message. |
| 6443 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6444 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6445 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 6446 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6447 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6448 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6449 | // Wrong password. |
| 6450 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6451 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 6452 | MockRead("Content-Length: 42\r\n"), |
| 6453 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6454 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6455 | }; |
| 6456 | |
| 6457 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6458 | // After restarting with a null identity, this is the |
| 6459 | // request we should be issuing -- the final header line contains a Type |
| 6460 | // 1 message. |
| 6461 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6462 | "Host: 172.22.68.17\r\n" |
| 6463 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6464 | "Authorization: NTLM "), |
| 6465 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6466 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6467 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6468 | // (the credentials for the origin server). The second request continues |
| 6469 | // on the same connection. |
| 6470 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6471 | "Host: 172.22.68.17\r\n" |
| 6472 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6473 | "Authorization: NTLM "), |
| 6474 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6475 | }; |
| 6476 | |
| 6477 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6478 | // The origin server responds with a Type 2 message. |
| 6479 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6480 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6481 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6482 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6483 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6484 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6485 | // Lastly we get the desired content. |
| 6486 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6487 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6488 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6489 | }; |
| 6490 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6491 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6492 | data_writes1, arraysize(data_writes1)); |
| 6493 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6494 | data_writes2, arraysize(data_writes2)); |
| 6495 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6496 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6497 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6498 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6499 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6500 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6501 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6503 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6504 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6505 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6506 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6507 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6508 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6509 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6510 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6511 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6512 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6513 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6514 | |
| 6515 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6516 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6517 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6518 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6519 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6520 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6521 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6522 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6523 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6524 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6525 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6526 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6527 | rv = trans.RestartWithAuth( |
| 6528 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 6529 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6530 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6531 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6532 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6533 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6534 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6535 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6536 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6537 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6538 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6539 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6540 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6541 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6542 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6543 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6544 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6545 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6546 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6547 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6548 | |
| 6549 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6550 | rv = trans.RestartWithAuth( |
| 6551 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6552 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6553 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6554 | |
| 6555 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6556 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6558 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6559 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6560 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6561 | |
| 6562 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6563 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6564 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6565 | |
| 6566 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6567 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6568 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6569 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6570 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6571 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6572 | |
| 6573 | std::string response_data; |
| 6574 | rv = ReadTransaction(&trans, &response_data); |
| 6575 | EXPECT_THAT(rv, IsOk()); |
| 6576 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6577 | |
| 6578 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6579 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6580 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6581 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6582 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6583 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6584 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6585 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6586 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 6587 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6588 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6589 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6590 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6591 | |
| 6592 | const char* kUrl = "https://172.22.68.17/kids/login.aspx"; |
| 6593 | |
| 6594 | HttpRequestInfo request; |
| 6595 | request.method = "GET"; |
| 6596 | request.url = GURL(kUrl); |
| 6597 | |
| 6598 | // First request without credentials. |
| 6599 | SpdyHeaderBlock request_headers0(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6600 | SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
| 6601 | 1, std::move(request_headers0), LOWEST, true)); |
| 6602 | |
| 6603 | SpdyHeaderBlock response_headers0; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 6604 | response_headers0[kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6605 | response_headers0["www-authenticate"] = "NTLM"; |
| 6606 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
| 6607 | 1, std::move(response_headers0), true)); |
| 6608 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6609 | // Stream 1 is closed. |
| 6610 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6611 | |
| 6612 | // Generate the NTLM messages based on known test data. |
| 6613 | std::string negotiate_msg; |
| 6614 | std::string challenge_msg; |
| 6615 | std::string authenticate_msg; |
| 6616 | base::Base64Encode( |
| 6617 | base::StringPiece( |
| 6618 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6619 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6620 | &negotiate_msg); |
| 6621 | base::Base64Encode(base::StringPiece(reinterpret_cast<const char*>( |
| 6622 | ntlm::test::kChallengeMsgV1), |
| 6623 | arraysize(ntlm::test::kChallengeMsgV1)), |
| 6624 | &challenge_msg); |
| 6625 | base::Base64Encode( |
| 6626 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6627 | reinterpret_cast<const char*>( |
| 6628 | ntlm::test::kExpectedAuthenticateMsgSpecResponseV1), |
| 6629 | arraysize(ntlm::test::kExpectedAuthenticateMsgSpecResponseV1)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6630 | &authenticate_msg); |
| 6631 | |
| 6632 | // Retry with authorization header. |
| 6633 | SpdyHeaderBlock request_headers1(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6634 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
| 6635 | SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
| 6636 | 3, std::move(request_headers1), LOWEST, true)); |
| 6637 | |
| 6638 | SpdySerializedFrame rst( |
| 6639 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_HTTP_1_1_REQUIRED)); |
| 6640 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6641 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 6642 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6643 | |
| 6644 | // Retry yet again using HTTP/1.1. |
| 6645 | MockWrite writes1[] = { |
| 6646 | // After restarting with a null identity, this is the |
| 6647 | // request we should be issuing -- the final header line contains a Type |
| 6648 | // 1 message. |
| 6649 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6650 | "Host: 172.22.68.17\r\n" |
| 6651 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6652 | "Authorization: NTLM "), |
| 6653 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6654 | |
| 6655 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6656 | // (the credentials for the origin server). The second request continues |
| 6657 | // on the same connection. |
| 6658 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6659 | "Host: 172.22.68.17\r\n" |
| 6660 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6661 | "Authorization: NTLM "), |
| 6662 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6663 | }; |
| 6664 | |
| 6665 | MockRead reads1[] = { |
| 6666 | // The origin server responds with a Type 2 message. |
| 6667 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6668 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6669 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6670 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6671 | MockRead("You are not authorized to view this page\r\n"), |
| 6672 | |
| 6673 | // Lastly we get the desired content. |
| 6674 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6675 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6676 | 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] | 6677 | }; |
| 6678 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 6679 | arraysize(writes0)); |
| 6680 | StaticSocketDataProvider data1(reads1, arraysize(reads1), writes1, |
| 6681 | arraysize(writes1)); |
| 6682 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6683 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6684 | |
| 6685 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6686 | ssl0.next_proto = kProtoHTTP2; |
| 6687 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6688 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6689 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6690 | |
| 6691 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6692 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6693 | |
| 6694 | TestCompletionCallback callback1; |
| 6695 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6697 | |
| 6698 | rv = callback1.WaitForResult(); |
| 6699 | EXPECT_THAT(rv, IsOk()); |
| 6700 | |
| 6701 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6702 | |
| 6703 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6704 | ASSERT_TRUE(response); |
| 6705 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6706 | |
| 6707 | TestCompletionCallback callback2; |
| 6708 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6709 | rv = trans.RestartWithAuth( |
| 6710 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6711 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6712 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6713 | |
| 6714 | rv = callback2.WaitForResult(); |
| 6715 | EXPECT_THAT(rv, IsOk()); |
| 6716 | |
| 6717 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6718 | |
| 6719 | response = trans.GetResponseInfo(); |
| 6720 | ASSERT_TRUE(response); |
| 6721 | EXPECT_FALSE(response->auth_challenge); |
| 6722 | |
| 6723 | TestCompletionCallback callback3; |
| 6724 | |
| 6725 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6726 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6727 | |
| 6728 | rv = callback3.WaitForResult(); |
| 6729 | EXPECT_THAT(rv, IsOk()); |
| 6730 | |
| 6731 | response = trans.GetResponseInfo(); |
| 6732 | ASSERT_TRUE(response); |
| 6733 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6734 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6735 | |
| 6736 | std::string response_data; |
| 6737 | rv = ReadTransaction(&trans, &response_data); |
| 6738 | EXPECT_THAT(rv, IsOk()); |
| 6739 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6740 | |
| 6741 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6742 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6743 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6744 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6745 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6746 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6747 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6748 | // Test reading a server response which has only headers, and no body. |
| 6749 | // After some maximum number of bytes is consumed, the transaction should |
| 6750 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6751 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6752 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6753 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6754 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6755 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6756 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6757 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6758 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6759 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6760 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6761 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6762 | |
| 6763 | MockRead data_reads[] = { |
| 6764 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6765 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6766 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6767 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6768 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6769 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6770 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6771 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6772 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6773 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6774 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6775 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6776 | |
| 6777 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6778 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6779 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6780 | |
| 6781 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6782 | // establish tunnel. |
| 6783 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6784 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6785 | HttpRequestInfo request; |
| 6786 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6787 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6788 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6789 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6790 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6791 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6792 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6793 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6794 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6795 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6796 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6797 | // Since we have proxy, should try to establish tunnel. |
| 6798 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6799 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6800 | "Host: www.example.org:443\r\n" |
| 6801 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6802 | }; |
| 6803 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6804 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6805 | // connection. Usually a proxy would return 501 (not implemented), |
| 6806 | // or 200 (tunnel established). |
| 6807 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6808 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6809 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6810 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6811 | }; |
| 6812 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6813 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6814 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6815 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6817 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6818 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6819 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6821 | |
| 6822 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6823 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6824 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6825 | // Empty the current queue. This is necessary because idle sockets are |
| 6826 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6827 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6828 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6829 | // We now check to make sure the TCPClientSocket was not added back to |
| 6830 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6831 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6832 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6833 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6834 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6835 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6836 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6837 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6838 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6839 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6840 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6841 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6842 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6843 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6844 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6845 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6846 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6847 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6848 | MockRead data_reads[] = { |
| 6849 | // A part of the response body is received with the response headers. |
| 6850 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6851 | // The rest of the response body is received in two parts. |
| 6852 | MockRead("lo"), |
| 6853 | MockRead(" world"), |
| 6854 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6855 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6856 | }; |
| 6857 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6858 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6859 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6860 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6861 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6862 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6863 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6864 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6865 | |
| 6866 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6867 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6869 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6870 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6871 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6872 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6873 | std::string status_line = response->headers->GetStatusLine(); |
| 6874 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6875 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6876 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6877 | |
| 6878 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6879 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6880 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6881 | EXPECT_EQ("hello world", response_data); |
| 6882 | |
| 6883 | // Empty the current queue. This is necessary because idle sockets are |
| 6884 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6885 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6886 | |
| 6887 | // 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] | 6888 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6889 | } |
| 6890 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6891 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6892 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6893 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6894 | HttpRequestInfo request; |
| 6895 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6896 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6897 | |
| 6898 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6899 | MockWrite( |
| 6900 | "GET / HTTP/1.1\r\n" |
| 6901 | "Host: www.example.org\r\n" |
| 6902 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6903 | }; |
| 6904 | |
| 6905 | MockRead data_reads[] = { |
| 6906 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6907 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6908 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6909 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6910 | }; |
| 6911 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6912 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6913 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6914 | |
| 6915 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6916 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6917 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6918 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6919 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6920 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6921 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6922 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6923 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6924 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6925 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6926 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6927 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6928 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6929 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6930 | ASSERT_TRUE(response); |
| 6931 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6932 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6933 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6934 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6935 | |
| 6936 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6937 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6938 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6939 | EXPECT_EQ("hello world", response_data); |
| 6940 | |
| 6941 | // Empty the current queue. This is necessary because idle sockets are |
| 6942 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6943 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6944 | |
| 6945 | // 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] | 6946 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6947 | } |
| 6948 | |
| 6949 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6950 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6951 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6952 | HttpRequestInfo request; |
| 6953 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6954 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6955 | |
| 6956 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6957 | MockWrite( |
| 6958 | "GET / HTTP/1.1\r\n" |
| 6959 | "Host: www.example.org\r\n" |
| 6960 | "Connection: keep-alive\r\n\r\n"), |
| 6961 | MockWrite( |
| 6962 | "GET / HTTP/1.1\r\n" |
| 6963 | "Host: www.example.org\r\n" |
| 6964 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6965 | }; |
| 6966 | |
| 6967 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6968 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6969 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6970 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6971 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6972 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6973 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6974 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6975 | |
| 6976 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6977 | data_writes, arraysize(data_writes)); |
| 6978 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6979 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6980 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6981 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6982 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6983 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6984 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6985 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6986 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6987 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6988 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6989 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6990 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6991 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6992 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6993 | |
| 6994 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6995 | ASSERT_TRUE(response); |
| 6996 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6997 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6998 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6999 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7000 | |
| 7001 | std::string response_data; |
| 7002 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7003 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7004 | EXPECT_EQ("hello world", response_data); |
| 7005 | |
| 7006 | // Empty the current queue. This is necessary because idle sockets are |
| 7007 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7008 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7009 | |
| 7010 | // 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] | 7011 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7012 | |
| 7013 | // Now start the second transaction, which should reuse the previous socket. |
| 7014 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7015 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7016 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7017 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7018 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7019 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7021 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7022 | |
| 7023 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7024 | ASSERT_TRUE(response); |
| 7025 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7026 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7027 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7028 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7029 | |
| 7030 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7031 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7032 | EXPECT_EQ("hello world", response_data); |
| 7033 | |
| 7034 | // Empty the current queue. This is necessary because idle sockets are |
| 7035 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7036 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7037 | |
| 7038 | // 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] | 7039 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7040 | } |
| 7041 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7042 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7043 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7044 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7045 | HttpRequestInfo request; |
| 7046 | request.method = "GET"; |
| 7047 | request.url = GURL("http://www.example.org/"); |
| 7048 | request.load_flags = 0; |
| 7049 | |
| 7050 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7051 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7052 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7053 | |
| 7054 | MockRead data_reads[] = { |
| 7055 | // A part of the response body is received with the response headers. |
| 7056 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7057 | // The rest of the response body is received in two parts. |
| 7058 | MockRead("lo"), MockRead(" world"), |
| 7059 | MockRead("junk"), // Should not be read!! |
| 7060 | MockRead(SYNCHRONOUS, OK), |
| 7061 | }; |
| 7062 | |
| 7063 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7064 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7065 | |
| 7066 | TestCompletionCallback callback; |
| 7067 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7068 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7069 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7070 | |
| 7071 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7072 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7073 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7074 | ASSERT_TRUE(response); |
| 7075 | EXPECT_TRUE(response->headers); |
| 7076 | std::string status_line = response->headers->GetStatusLine(); |
| 7077 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7078 | |
| 7079 | // Make memory critical notification and ensure the transaction still has been |
| 7080 | // operating right. |
| 7081 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7082 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7083 | base::RunLoop().RunUntilIdle(); |
| 7084 | |
| 7085 | // Socket should not be flushed as long as it is not idle. |
| 7086 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7087 | |
| 7088 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7089 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7090 | EXPECT_THAT(rv, IsOk()); |
| 7091 | EXPECT_EQ("hello world", response_data); |
| 7092 | |
| 7093 | // Empty the current queue. This is necessary because idle sockets are |
| 7094 | // added to the connection pool asynchronously with a PostTask. |
| 7095 | base::RunLoop().RunUntilIdle(); |
| 7096 | |
| 7097 | // We now check to make sure the socket was added back to the pool. |
| 7098 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7099 | |
| 7100 | // Idle sockets should be flushed now. |
| 7101 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7102 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7103 | base::RunLoop().RunUntilIdle(); |
| 7104 | |
| 7105 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7106 | } |
| 7107 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7108 | // Disable idle socket closing on memory pressure. |
| 7109 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7110 | // low memory notification and ensure the socket pool is NOT flushed. |
| 7111 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 7112 | HttpRequestInfo request; |
| 7113 | request.method = "GET"; |
| 7114 | request.url = GURL("http://www.example.org/"); |
| 7115 | request.load_flags = 0; |
| 7116 | |
| 7117 | // Disable idle socket closing on memory pressure. |
| 7118 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 7119 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7120 | |
| 7121 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7122 | |
| 7123 | MockRead data_reads[] = { |
| 7124 | // A part of the response body is received with the response headers. |
| 7125 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7126 | // The rest of the response body is received in two parts. |
| 7127 | MockRead("lo"), MockRead(" world"), |
| 7128 | MockRead("junk"), // Should not be read!! |
| 7129 | MockRead(SYNCHRONOUS, OK), |
| 7130 | }; |
| 7131 | |
| 7132 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7133 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7134 | |
| 7135 | TestCompletionCallback callback; |
| 7136 | |
| 7137 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 7138 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7139 | |
| 7140 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7141 | |
| 7142 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7143 | ASSERT_TRUE(response); |
| 7144 | EXPECT_TRUE(response->headers); |
| 7145 | std::string status_line = response->headers->GetStatusLine(); |
| 7146 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7147 | |
| 7148 | // Make memory critical notification and ensure the transaction still has been |
| 7149 | // operating right. |
| 7150 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7151 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7152 | base::RunLoop().RunUntilIdle(); |
| 7153 | |
| 7154 | // Socket should not be flushed as long as it is not idle. |
| 7155 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7156 | |
| 7157 | std::string response_data; |
| 7158 | rv = ReadTransaction(&trans, &response_data); |
| 7159 | EXPECT_THAT(rv, IsOk()); |
| 7160 | EXPECT_EQ("hello world", response_data); |
| 7161 | |
| 7162 | // Empty the current queue. This is necessary because idle sockets are |
| 7163 | // added to the connection pool asynchronously with a PostTask. |
| 7164 | base::RunLoop().RunUntilIdle(); |
| 7165 | |
| 7166 | // We now check to make sure the socket was added back to the pool. |
| 7167 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7168 | |
| 7169 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 7170 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7171 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 7172 | base::RunLoop().RunUntilIdle(); |
| 7173 | |
| 7174 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7175 | |
| 7176 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 7177 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7178 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7179 | base::RunLoop().RunUntilIdle(); |
| 7180 | |
| 7181 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7182 | } |
| 7183 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7184 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 7185 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7186 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7187 | HttpRequestInfo request; |
| 7188 | request.method = "GET"; |
| 7189 | request.url = GURL("https://www.example.org/"); |
| 7190 | request.load_flags = 0; |
| 7191 | |
| 7192 | MockWrite data_writes[] = { |
| 7193 | MockWrite("GET / HTTP/1.1\r\n" |
| 7194 | "Host: www.example.org\r\n" |
| 7195 | "Connection: keep-alive\r\n\r\n"), |
| 7196 | }; |
| 7197 | |
| 7198 | MockRead data_reads[] = { |
| 7199 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7200 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 7201 | |
| 7202 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7203 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7204 | |
| 7205 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 7206 | arraysize(data_writes)); |
| 7207 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7208 | |
| 7209 | TestCompletionCallback callback; |
| 7210 | |
| 7211 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7212 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7213 | |
| 7214 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7215 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7216 | |
| 7217 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7218 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7219 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7220 | ASSERT_TRUE(response); |
| 7221 | ASSERT_TRUE(response->headers); |
| 7222 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7223 | |
| 7224 | // Make memory critical notification and ensure the transaction still has been |
| 7225 | // operating right. |
| 7226 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7227 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7228 | base::RunLoop().RunUntilIdle(); |
| 7229 | |
| 7230 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7231 | |
| 7232 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7233 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7234 | EXPECT_THAT(rv, IsOk()); |
| 7235 | EXPECT_EQ("hello world", response_data); |
| 7236 | |
| 7237 | // Empty the current queue. This is necessary because idle sockets are |
| 7238 | // added to the connection pool asynchronously with a PostTask. |
| 7239 | base::RunLoop().RunUntilIdle(); |
| 7240 | |
| 7241 | // We now check to make sure the socket was added back to the pool. |
| 7242 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7243 | |
| 7244 | // Make memory notification once again and ensure idle socket is closed. |
| 7245 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7246 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7247 | base::RunLoop().RunUntilIdle(); |
| 7248 | |
| 7249 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7250 | } |
| 7251 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7252 | // Make sure that we recycle a socket after a zero-length response. |
| 7253 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7254 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7255 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7256 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7257 | request.url = GURL( |
| 7258 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 7259 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 7260 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 7261 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7262 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7263 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7264 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7265 | MockRead data_reads[] = { |
| 7266 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 7267 | "Content-Length: 0\r\n" |
| 7268 | "Content-Type: text/html\r\n\r\n"), |
| 7269 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7270 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7271 | }; |
| 7272 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7273 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7274 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7275 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7276 | // Transaction must be created after the MockReads, so it's destroyed before |
| 7277 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7278 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7279 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7280 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7281 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7282 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7283 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7284 | |
| 7285 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7286 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7287 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7288 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7289 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7290 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7291 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7292 | std::string status_line = response->headers->GetStatusLine(); |
| 7293 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 7294 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7295 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7296 | |
| 7297 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7298 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7299 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7300 | EXPECT_EQ("", response_data); |
| 7301 | |
| 7302 | // Empty the current queue. This is necessary because idle sockets are |
| 7303 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7304 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7305 | |
| 7306 | // 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] | 7307 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7308 | } |
| 7309 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7310 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7311 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7312 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7313 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7314 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7315 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7316 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7317 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 7318 | // after use. |
| 7319 | request[0].method = "GET"; |
| 7320 | request[0].url = GURL("http://www.google.com/"); |
| 7321 | request[0].load_flags = 0; |
| 7322 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 7323 | // transaction 1. The first attempts fails when writing the POST data. |
| 7324 | // This causes the transaction to retry with a new socket. The second |
| 7325 | // attempt succeeds. |
| 7326 | request[1].method = "POST"; |
| 7327 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7328 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7329 | request[1].load_flags = 0; |
| 7330 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7331 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7332 | |
| 7333 | // The first socket is used for transaction 1 and the first attempt of |
| 7334 | // transaction 2. |
| 7335 | |
| 7336 | // The response of transaction 1. |
| 7337 | MockRead data_reads1[] = { |
| 7338 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 7339 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7340 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7341 | }; |
| 7342 | // The mock write results of transaction 1 and the first attempt of |
| 7343 | // transaction 2. |
| 7344 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7345 | MockWrite(SYNCHRONOUS, 64), // GET |
| 7346 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7347 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7348 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7349 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7350 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7351 | |
| 7352 | // The second socket is used for the second attempt of transaction 2. |
| 7353 | |
| 7354 | // The response of transaction 2. |
| 7355 | MockRead data_reads2[] = { |
| 7356 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 7357 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7358 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7359 | }; |
| 7360 | // The mock write results of the second attempt of transaction 2. |
| 7361 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7362 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7363 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7364 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7365 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7366 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7367 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7368 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7369 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7370 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7371 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7372 | "hello world", "welcome" |
| 7373 | }; |
| 7374 | |
| 7375 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7376 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7377 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7378 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7379 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7380 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7381 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7382 | |
| 7383 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7384 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7385 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7386 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7387 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7388 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7389 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7390 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7391 | |
| 7392 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7393 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7394 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7395 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7396 | } |
| 7397 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7398 | |
| 7399 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7400 | // 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] | 7401 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7402 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7403 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7404 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7405 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7406 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7407 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7408 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7409 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7410 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7411 | // The password contains an escaped character -- for this test to pass it |
| 7412 | // will need to be unescaped by HttpNetworkTransaction. |
| 7413 | EXPECT_EQ("b%40r", request.url.password()); |
| 7414 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7415 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7416 | MockWrite( |
| 7417 | "GET / HTTP/1.1\r\n" |
| 7418 | "Host: www.example.org\r\n" |
| 7419 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7420 | }; |
| 7421 | |
| 7422 | MockRead data_reads1[] = { |
| 7423 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7424 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7425 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7426 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7427 | }; |
| 7428 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7429 | // After the challenge above, the transaction will be restarted using the |
| 7430 | // identity from the url (foo, b@r) to answer the challenge. |
| 7431 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7432 | MockWrite( |
| 7433 | "GET / HTTP/1.1\r\n" |
| 7434 | "Host: www.example.org\r\n" |
| 7435 | "Connection: keep-alive\r\n" |
| 7436 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7437 | }; |
| 7438 | |
| 7439 | MockRead data_reads2[] = { |
| 7440 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7441 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7442 | MockRead(SYNCHRONOUS, OK), |
| 7443 | }; |
| 7444 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7445 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7446 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7447 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7448 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7449 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7450 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7451 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7452 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7453 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7454 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7455 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7456 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7457 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7458 | |
| 7459 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7460 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7461 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7462 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7463 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7464 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7466 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7467 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7468 | |
| 7469 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7470 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7471 | |
| 7472 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7473 | |
| 7474 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7475 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7476 | } |
| 7477 | |
| 7478 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7479 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7480 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7481 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7482 | HttpRequestInfo request; |
| 7483 | request.method = "GET"; |
| 7484 | // Note: the URL has a username:password in it. The password "baz" is |
| 7485 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7486 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7487 | |
| 7488 | request.load_flags = LOAD_NORMAL; |
| 7489 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7490 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7491 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7492 | |
| 7493 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7494 | MockWrite( |
| 7495 | "GET / HTTP/1.1\r\n" |
| 7496 | "Host: www.example.org\r\n" |
| 7497 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7498 | }; |
| 7499 | |
| 7500 | MockRead data_reads1[] = { |
| 7501 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7502 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7503 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7504 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7505 | }; |
| 7506 | |
| 7507 | // After the challenge above, the transaction will be restarted using the |
| 7508 | // identity from the url (foo, baz) to answer the challenge. |
| 7509 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7510 | MockWrite( |
| 7511 | "GET / HTTP/1.1\r\n" |
| 7512 | "Host: www.example.org\r\n" |
| 7513 | "Connection: keep-alive\r\n" |
| 7514 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7515 | }; |
| 7516 | |
| 7517 | MockRead data_reads2[] = { |
| 7518 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7519 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7520 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7521 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7522 | }; |
| 7523 | |
| 7524 | // After the challenge above, the transaction will be restarted using the |
| 7525 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7526 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7527 | MockWrite( |
| 7528 | "GET / HTTP/1.1\r\n" |
| 7529 | "Host: www.example.org\r\n" |
| 7530 | "Connection: keep-alive\r\n" |
| 7531 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7532 | }; |
| 7533 | |
| 7534 | MockRead data_reads3[] = { |
| 7535 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7536 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7537 | MockRead(SYNCHRONOUS, OK), |
| 7538 | }; |
| 7539 | |
| 7540 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7541 | data_writes1, arraysize(data_writes1)); |
| 7542 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7543 | data_writes2, arraysize(data_writes2)); |
| 7544 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7545 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7546 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7547 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7548 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7549 | |
| 7550 | TestCompletionCallback callback1; |
| 7551 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7552 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7553 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7554 | |
| 7555 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7556 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7558 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7559 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7560 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7561 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7562 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7563 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7564 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7565 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7566 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7567 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7568 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7569 | |
| 7570 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7571 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7572 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7573 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7574 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7575 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7576 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7577 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7578 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7579 | |
| 7580 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7581 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7582 | |
| 7583 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7584 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7585 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7586 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7587 | } |
| 7588 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7589 | |
| 7590 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7591 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7592 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7593 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7594 | HttpRequestInfo request; |
| 7595 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7596 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7597 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7598 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7599 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7600 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7601 | |
| 7602 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7603 | MockWrite( |
| 7604 | "GET / HTTP/1.1\r\n" |
| 7605 | "Host: www.example.org\r\n" |
| 7606 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7607 | }; |
| 7608 | |
| 7609 | MockRead data_reads1[] = { |
| 7610 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7611 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7612 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7613 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7614 | }; |
| 7615 | |
| 7616 | // After the challenge above, the transaction will be restarted using the |
| 7617 | // identity supplied by the user, not the one in the URL, to answer the |
| 7618 | // challenge. |
| 7619 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7620 | MockWrite( |
| 7621 | "GET / HTTP/1.1\r\n" |
| 7622 | "Host: www.example.org\r\n" |
| 7623 | "Connection: keep-alive\r\n" |
| 7624 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7625 | }; |
| 7626 | |
| 7627 | MockRead data_reads3[] = { |
| 7628 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7629 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7630 | MockRead(SYNCHRONOUS, OK), |
| 7631 | }; |
| 7632 | |
| 7633 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7634 | data_writes1, arraysize(data_writes1)); |
| 7635 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7636 | data_writes3, arraysize(data_writes3)); |
| 7637 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7638 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7639 | |
| 7640 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7641 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7642 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7643 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7644 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7645 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7646 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7647 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7648 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7649 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7650 | |
| 7651 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7652 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7653 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7654 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7655 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7656 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7657 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7658 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7659 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7660 | |
| 7661 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7662 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7663 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7664 | |
| 7665 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7666 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7667 | } |
| 7668 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7669 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7670 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7671 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7672 | |
| 7673 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7674 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7675 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7676 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7677 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7678 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7679 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7680 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7681 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7682 | MockWrite( |
| 7683 | "GET /x/y/z HTTP/1.1\r\n" |
| 7684 | "Host: www.example.org\r\n" |
| 7685 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7686 | }; |
| 7687 | |
| 7688 | MockRead data_reads1[] = { |
| 7689 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7690 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7691 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7692 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7693 | }; |
| 7694 | |
| 7695 | // Resend with authorization (username=foo, password=bar) |
| 7696 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7697 | MockWrite( |
| 7698 | "GET /x/y/z HTTP/1.1\r\n" |
| 7699 | "Host: www.example.org\r\n" |
| 7700 | "Connection: keep-alive\r\n" |
| 7701 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7702 | }; |
| 7703 | |
| 7704 | // Sever accepts the authorization. |
| 7705 | MockRead data_reads2[] = { |
| 7706 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7707 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7708 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7709 | }; |
| 7710 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7711 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7712 | data_writes1, arraysize(data_writes1)); |
| 7713 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7714 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7715 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7716 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7717 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7718 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7719 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7720 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7721 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7722 | |
| 7723 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7724 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7725 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7726 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7727 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7728 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7729 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7730 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7731 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7732 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7733 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7734 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7735 | |
| 7736 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7737 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7738 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7739 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7740 | ASSERT_TRUE(response); |
| 7741 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7742 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7743 | } |
| 7744 | |
| 7745 | // ------------------------------------------------------------------------ |
| 7746 | |
| 7747 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7748 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7749 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7750 | request.method = "GET"; |
| 7751 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7752 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7753 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7755 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7756 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7757 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7758 | MockWrite( |
| 7759 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7760 | "Host: www.example.org\r\n" |
| 7761 | "Connection: keep-alive\r\n" |
| 7762 | // Send preemptive authorization for MyRealm1 |
| 7763 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7764 | }; |
| 7765 | |
| 7766 | // The server didn't like the preemptive authorization, and |
| 7767 | // challenges us for a different realm (MyRealm2). |
| 7768 | MockRead data_reads1[] = { |
| 7769 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7770 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7771 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7772 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7773 | }; |
| 7774 | |
| 7775 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7776 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7777 | MockWrite( |
| 7778 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7779 | "Host: www.example.org\r\n" |
| 7780 | "Connection: keep-alive\r\n" |
| 7781 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7782 | }; |
| 7783 | |
| 7784 | // Sever accepts the authorization. |
| 7785 | MockRead data_reads2[] = { |
| 7786 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7787 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7788 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7789 | }; |
| 7790 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7791 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7792 | data_writes1, arraysize(data_writes1)); |
| 7793 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7794 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7795 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7796 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7798 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7799 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7800 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7801 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7802 | |
| 7803 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7804 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7805 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7806 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7807 | ASSERT_TRUE(response); |
| 7808 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7809 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7810 | EXPECT_EQ("http://www.example.org", |
| 7811 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7812 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7813 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7814 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7815 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7816 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7817 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7818 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7819 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7820 | |
| 7821 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7822 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7823 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7824 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7825 | ASSERT_TRUE(response); |
| 7826 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7827 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7828 | } |
| 7829 | |
| 7830 | // ------------------------------------------------------------------------ |
| 7831 | |
| 7832 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7833 | // succeed with preemptive authorization. |
| 7834 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7835 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7836 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7837 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7839 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7840 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7841 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7842 | MockWrite( |
| 7843 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7844 | "Host: www.example.org\r\n" |
| 7845 | "Connection: keep-alive\r\n" |
| 7846 | // The authorization for MyRealm1 gets sent preemptively |
| 7847 | // (since the url is in the same protection space) |
| 7848 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7849 | }; |
| 7850 | |
| 7851 | // Sever accepts the preemptive authorization |
| 7852 | MockRead data_reads1[] = { |
| 7853 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7854 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7855 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7856 | }; |
| 7857 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7858 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7859 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7860 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7861 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7862 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7863 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7864 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7866 | |
| 7867 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7868 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7869 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7870 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7871 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7872 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7873 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7874 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7875 | } |
| 7876 | |
| 7877 | // ------------------------------------------------------------------------ |
| 7878 | |
| 7879 | // Transaction 4: request another URL in MyRealm (however the |
| 7880 | // url is not known to belong to the protection space, so no pre-auth). |
| 7881 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7882 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7883 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7884 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7885 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7886 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7887 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7888 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7889 | MockWrite( |
| 7890 | "GET /x/1 HTTP/1.1\r\n" |
| 7891 | "Host: www.example.org\r\n" |
| 7892 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7893 | }; |
| 7894 | |
| 7895 | MockRead data_reads1[] = { |
| 7896 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7897 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7898 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7899 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7900 | }; |
| 7901 | |
| 7902 | // Resend with authorization from MyRealm's cache. |
| 7903 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7904 | MockWrite( |
| 7905 | "GET /x/1 HTTP/1.1\r\n" |
| 7906 | "Host: www.example.org\r\n" |
| 7907 | "Connection: keep-alive\r\n" |
| 7908 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7909 | }; |
| 7910 | |
| 7911 | // Sever accepts the authorization. |
| 7912 | MockRead data_reads2[] = { |
| 7913 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7914 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7915 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7916 | }; |
| 7917 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7918 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7919 | data_writes1, arraysize(data_writes1)); |
| 7920 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7921 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7922 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7923 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7925 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7926 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7927 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7928 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7929 | |
| 7930 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7931 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7932 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7933 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7934 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7935 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7936 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7937 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7938 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7939 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7940 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7941 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7942 | ASSERT_TRUE(response); |
| 7943 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7944 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7945 | } |
| 7946 | |
| 7947 | // ------------------------------------------------------------------------ |
| 7948 | |
| 7949 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7950 | // cached identity. Should invalidate and re-prompt. |
| 7951 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7952 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7953 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7954 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7955 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7956 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7957 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7958 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7959 | MockWrite( |
| 7960 | "GET /p/q/t HTTP/1.1\r\n" |
| 7961 | "Host: www.example.org\r\n" |
| 7962 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7963 | }; |
| 7964 | |
| 7965 | MockRead data_reads1[] = { |
| 7966 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7967 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7968 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7969 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7970 | }; |
| 7971 | |
| 7972 | // Resend with authorization from cache for MyRealm. |
| 7973 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7974 | MockWrite( |
| 7975 | "GET /p/q/t HTTP/1.1\r\n" |
| 7976 | "Host: www.example.org\r\n" |
| 7977 | "Connection: keep-alive\r\n" |
| 7978 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7979 | }; |
| 7980 | |
| 7981 | // Sever rejects the authorization. |
| 7982 | MockRead data_reads2[] = { |
| 7983 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7984 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7985 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7986 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7987 | }; |
| 7988 | |
| 7989 | // At this point we should prompt for new credentials for MyRealm. |
| 7990 | // Restart with username=foo3, password=foo4. |
| 7991 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7992 | MockWrite( |
| 7993 | "GET /p/q/t HTTP/1.1\r\n" |
| 7994 | "Host: www.example.org\r\n" |
| 7995 | "Connection: keep-alive\r\n" |
| 7996 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7997 | }; |
| 7998 | |
| 7999 | // Sever accepts the authorization. |
| 8000 | MockRead data_reads3[] = { |
| 8001 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8002 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8003 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8004 | }; |
| 8005 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8006 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8007 | data_writes1, arraysize(data_writes1)); |
| 8008 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8009 | data_writes2, arraysize(data_writes2)); |
| 8010 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8011 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8012 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8013 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8014 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8015 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8016 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8017 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8018 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8019 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8020 | |
| 8021 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8022 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8023 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8024 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8025 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8026 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8027 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8028 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8029 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8030 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8031 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8032 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8033 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8034 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8035 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8036 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8037 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8038 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 8039 | callback3.callback()); |
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 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8042 | rv = callback3.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 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8046 | ASSERT_TRUE(response); |
| 8047 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8048 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8049 | } |
| 8050 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8051 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8052 | // Tests that nonce count increments when multiple auth attempts |
| 8053 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8054 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 8055 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 8056 | new HttpAuthHandlerDigest::Factory(); |
| 8057 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 8058 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 8059 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8060 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8061 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8062 | |
| 8063 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8064 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8065 | HttpRequestInfo request; |
| 8066 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8067 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8068 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8069 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8070 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8071 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8072 | MockWrite( |
| 8073 | "GET /x/y/z HTTP/1.1\r\n" |
| 8074 | "Host: www.example.org\r\n" |
| 8075 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8076 | }; |
| 8077 | |
| 8078 | MockRead data_reads1[] = { |
| 8079 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8080 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 8081 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8082 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8083 | }; |
| 8084 | |
| 8085 | // Resend with authorization (username=foo, password=bar) |
| 8086 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8087 | MockWrite( |
| 8088 | "GET /x/y/z HTTP/1.1\r\n" |
| 8089 | "Host: www.example.org\r\n" |
| 8090 | "Connection: keep-alive\r\n" |
| 8091 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8092 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 8093 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 8094 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8095 | }; |
| 8096 | |
| 8097 | // Sever accepts the authorization. |
| 8098 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8099 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8100 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8101 | }; |
| 8102 | |
| 8103 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8104 | data_writes1, arraysize(data_writes1)); |
| 8105 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8106 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8107 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8108 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8109 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8110 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8111 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8112 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8113 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8114 | |
| 8115 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8116 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8117 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8118 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8119 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8120 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8121 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8122 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8123 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8124 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8125 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8126 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8127 | |
| 8128 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8129 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8130 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8131 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8132 | ASSERT_TRUE(response); |
| 8133 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8134 | } |
| 8135 | |
| 8136 | // ------------------------------------------------------------------------ |
| 8137 | |
| 8138 | // Transaction 2: Request another resource in digestive's protection space. |
| 8139 | // This will preemptively add an Authorization header which should have an |
| 8140 | // "nc" value of 2 (as compared to 1 in the first use. |
| 8141 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8142 | HttpRequestInfo request; |
| 8143 | request.method = "GET"; |
| 8144 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8145 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8146 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8147 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8148 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8149 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8150 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8151 | MockWrite( |
| 8152 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8153 | "Host: www.example.org\r\n" |
| 8154 | "Connection: keep-alive\r\n" |
| 8155 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8156 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 8157 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 8158 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8159 | }; |
| 8160 | |
| 8161 | // Sever accepts the authorization. |
| 8162 | MockRead data_reads1[] = { |
| 8163 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8164 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8165 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8166 | }; |
| 8167 | |
| 8168 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8169 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8170 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8171 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8172 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8173 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8174 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8175 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8176 | |
| 8177 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8178 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8179 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8180 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8181 | ASSERT_TRUE(response); |
| 8182 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8183 | } |
| 8184 | } |
| 8185 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8186 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8187 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8188 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8189 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8190 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8191 | |
| 8192 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8193 | trans.read_buf_ = new IOBuffer(15); |
| 8194 | trans.read_buf_len_ = 15; |
| 8195 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8196 | |
| 8197 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8198 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8199 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8200 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8201 | response->response_time = base::Time::Now(); |
| 8202 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8203 | |
| 8204 | { // Setup state for response_.vary_data |
| 8205 | HttpRequestInfo request; |
| 8206 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 8207 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 8208 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8209 | request.extra_headers.SetHeader("Foo", "1"); |
| 8210 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8211 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8212 | } |
| 8213 | |
| 8214 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8215 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8216 | |
| 8217 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8218 | EXPECT_FALSE(trans.read_buf_); |
| 8219 | EXPECT_EQ(0, trans.read_buf_len_); |
| 8220 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8221 | EXPECT_FALSE(response->auth_challenge); |
| 8222 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 8223 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8224 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8225 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8226 | } |
| 8227 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8228 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8229 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8230 | HttpRequestInfo request; |
| 8231 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8232 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8233 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8234 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8235 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8236 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8237 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8238 | MockWrite( |
| 8239 | "GET / HTTP/1.1\r\n" |
| 8240 | "Host: www.example.org\r\n" |
| 8241 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8242 | }; |
| 8243 | |
| 8244 | MockRead data_reads[] = { |
| 8245 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8246 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8247 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8248 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8249 | }; |
| 8250 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 8251 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8252 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8253 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8254 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8255 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8256 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8257 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8258 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8259 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8260 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8262 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8263 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8264 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8265 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8266 | |
| 8267 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8268 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8269 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8270 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8271 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8272 | |
| 8273 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8274 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8275 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8276 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8277 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8278 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8279 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8280 | } |
| 8281 | |
| 8282 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 8283 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8284 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8285 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8286 | |
| 8287 | HttpRequestInfo request; |
| 8288 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8289 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8290 | |
| 8291 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8292 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8293 | "Host: www.example.org:443\r\n" |
| 8294 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8295 | }; |
| 8296 | |
| 8297 | MockRead proxy_reads[] = { |
| 8298 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8299 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8300 | }; |
| 8301 | |
| 8302 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8303 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8304 | "Host: www.example.org:443\r\n" |
| 8305 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8306 | MockWrite("GET / HTTP/1.1\r\n" |
| 8307 | "Host: www.example.org\r\n" |
| 8308 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8309 | }; |
| 8310 | |
| 8311 | MockRead data_reads[] = { |
| 8312 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8313 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8314 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8315 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8316 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8317 | }; |
| 8318 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8319 | StaticSocketDataProvider ssl_bad_certificate( |
| 8320 | proxy_reads, arraysize(proxy_reads), |
| 8321 | proxy_writes, arraysize(proxy_writes)); |
| 8322 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8323 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8324 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8325 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8326 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8327 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8328 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8329 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8330 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8331 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8332 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8333 | |
| 8334 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8335 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8336 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8337 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8338 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8339 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8340 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8342 | |
| 8343 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8344 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8345 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8346 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8347 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8348 | |
| 8349 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8350 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8351 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8352 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8353 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8354 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8355 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8356 | } |
| 8357 | } |
| 8358 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8359 | |
| 8360 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8361 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8362 | session_deps_.proxy_service = |
| 8363 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8364 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8365 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8366 | |
| 8367 | HttpRequestInfo request; |
| 8368 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8369 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8370 | |
| 8371 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8372 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8373 | "Host: www.example.org:443\r\n" |
| 8374 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8375 | MockWrite("GET / HTTP/1.1\r\n" |
| 8376 | "Host: www.example.org\r\n" |
| 8377 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8378 | }; |
| 8379 | |
| 8380 | MockRead data_reads[] = { |
| 8381 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8382 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8383 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8384 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8385 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8386 | }; |
| 8387 | |
| 8388 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8389 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8390 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8391 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8392 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8393 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8394 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8395 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8396 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8397 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8398 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8399 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8400 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8401 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8402 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8403 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8404 | |
| 8405 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8406 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8407 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8408 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8409 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8410 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8411 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8412 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8413 | EXPECT_EQ(200, response->headers->response_code()); |
| 8414 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8415 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8416 | |
| 8417 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8418 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8419 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8420 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8421 | } |
| 8422 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8423 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8424 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8425 | session_deps_.proxy_service = |
| 8426 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8427 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8428 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8429 | |
| 8430 | HttpRequestInfo request; |
| 8431 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8432 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8433 | |
| 8434 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8435 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8436 | "Host: www.example.org:443\r\n" |
| 8437 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8438 | }; |
| 8439 | |
| 8440 | MockRead data_reads[] = { |
| 8441 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8442 | MockRead("Location: http://login.example.com/\r\n"), |
| 8443 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8444 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8445 | }; |
| 8446 | |
| 8447 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8448 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8449 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8450 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8451 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8452 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8453 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8454 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8455 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8456 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8457 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8458 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8459 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8460 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8461 | |
| 8462 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8463 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8464 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8465 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8466 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8467 | |
| 8468 | EXPECT_EQ(302, response->headers->response_code()); |
| 8469 | std::string url; |
| 8470 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8471 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8472 | |
| 8473 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8474 | // timing for the proxy connection instead of the connection to the host, |
| 8475 | // and no send / receive times. |
| 8476 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8477 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8478 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8479 | |
| 8480 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8481 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8482 | |
| 8483 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8484 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8485 | load_timing_info.proxy_resolve_end); |
| 8486 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8487 | load_timing_info.connect_timing.connect_start); |
| 8488 | ExpectConnectTimingHasTimes( |
| 8489 | load_timing_info.connect_timing, |
| 8490 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8491 | |
| 8492 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8493 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8494 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8495 | } |
| 8496 | |
| 8497 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8498 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8499 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8500 | |
| 8501 | HttpRequestInfo request; |
| 8502 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8503 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8504 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8505 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8506 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8507 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8508 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8509 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8510 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8511 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8512 | }; |
| 8513 | |
| 8514 | static const char* const kExtraHeaders[] = { |
| 8515 | "location", |
| 8516 | "http://login.example.com/", |
| 8517 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8518 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8519 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8520 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8521 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8522 | }; |
| 8523 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8524 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8525 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8526 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8527 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8528 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8529 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8530 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8531 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8532 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8533 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8534 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8535 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8536 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8537 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8538 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8539 | |
| 8540 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8541 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8542 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8543 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8544 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8545 | |
| 8546 | EXPECT_EQ(302, response->headers->response_code()); |
| 8547 | std::string url; |
| 8548 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8549 | EXPECT_EQ("http://login.example.com/", url); |
| 8550 | } |
| 8551 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8552 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8553 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8554 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8555 | |
| 8556 | HttpRequestInfo request; |
| 8557 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8558 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8559 | |
| 8560 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8561 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8562 | "Host: www.example.org:443\r\n" |
| 8563 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8564 | }; |
| 8565 | |
| 8566 | MockRead data_reads[] = { |
| 8567 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8568 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8569 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8570 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8571 | }; |
| 8572 | |
| 8573 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8574 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8575 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8576 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8577 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8578 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8579 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8580 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8581 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8582 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8583 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8584 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8585 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8586 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8587 | |
| 8588 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8589 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8590 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8591 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8592 | } |
| 8593 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8594 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8595 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8596 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8597 | |
| 8598 | HttpRequestInfo request; |
| 8599 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8600 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8601 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8602 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8603 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8604 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8605 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8606 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8607 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8608 | }; |
| 8609 | |
| 8610 | static const char* const kExtraHeaders[] = { |
| 8611 | "location", |
| 8612 | "http://login.example.com/", |
| 8613 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8614 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8615 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8616 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8617 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8618 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8619 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8620 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8621 | }; |
| 8622 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8623 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8624 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8625 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8626 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8627 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8628 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8629 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8630 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8631 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8632 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8633 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8634 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8635 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8636 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8638 | |
| 8639 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8640 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8641 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8642 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8643 | } |
| 8644 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8645 | // Test the request-challenge-retry sequence for basic auth, through |
| 8646 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8647 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8648 | HttpRequestInfo request; |
| 8649 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8650 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8651 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8652 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8653 | |
| 8654 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8655 | session_deps_.proxy_service = |
| 8656 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8657 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8658 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8660 | |
| 8661 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8662 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8663 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8664 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8665 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8666 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8667 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8668 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8669 | // be issuing -- the final header line contains the credentials. |
| 8670 | const char* const kAuthCredentials[] = { |
| 8671 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8672 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8673 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8674 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8675 | HostPortPair("www.example.org", 443))); |
| 8676 | // fetch https://www.example.org/ via HTTP |
| 8677 | const char get[] = |
| 8678 | "GET / HTTP/1.1\r\n" |
| 8679 | "Host: www.example.org\r\n" |
| 8680 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8681 | SpdySerializedFrame wrapped_get( |
| 8682 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8683 | |
| 8684 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8685 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8686 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8687 | }; |
| 8688 | |
| 8689 | // The proxy responds to the connect with a 407, using a persistent |
| 8690 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8691 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8692 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8693 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8694 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8695 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8696 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8697 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8698 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8699 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8700 | "Content-Length: 5\r\n\r\n"; |
| 8701 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8702 | SpdySerializedFrame wrapped_get_resp( |
| 8703 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8704 | SpdySerializedFrame wrapped_body( |
| 8705 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8706 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8707 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8708 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8709 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8710 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8711 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8712 | }; |
| 8713 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8714 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8715 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8716 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8717 | // Negotiate SPDY to the proxy |
| 8718 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8719 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8720 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8721 | // Vanilla SSL to the server |
| 8722 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8724 | |
| 8725 | TestCompletionCallback callback1; |
| 8726 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8727 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8728 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8729 | |
| 8730 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8731 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8732 | |
| 8733 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8734 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8735 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8736 | log.GetEntries(&entries); |
| 8737 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8738 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8739 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8740 | ExpectLogContainsSomewhere( |
| 8741 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8742 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8743 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8744 | |
| 8745 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8746 | ASSERT_TRUE(response); |
| 8747 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8748 | EXPECT_EQ(407, response->headers->response_code()); |
| 8749 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8750 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8751 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8752 | |
| 8753 | TestCompletionCallback callback2; |
| 8754 | |
| 8755 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8756 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8757 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8758 | |
| 8759 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8760 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8761 | |
| 8762 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8763 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8764 | |
| 8765 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8766 | EXPECT_EQ(200, response->headers->response_code()); |
| 8767 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8768 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8769 | |
| 8770 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8771 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8772 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8773 | LoadTimingInfo load_timing_info; |
| 8774 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8775 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8776 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8777 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8778 | trans.reset(); |
| 8779 | session->CloseAllConnections(); |
| 8780 | } |
| 8781 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8782 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8783 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8784 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8785 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8786 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8787 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8788 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8789 | HttpRequestInfo request; |
| 8790 | HttpRequestInfo push_request; |
| 8791 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8792 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8793 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8794 | push_request.method = "GET"; |
| 8795 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8796 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8797 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8798 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8799 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8800 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8801 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8802 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8803 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8804 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8805 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8806 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8807 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8808 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8809 | SpdySerializedFrame stream2_priority( |
| 8810 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8811 | |
| 8812 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8813 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8814 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8815 | }; |
| 8816 | |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 8817 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
| 8818 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 8819 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8820 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8821 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8822 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8823 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8824 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8825 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8826 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8827 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8828 | |
| 8829 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 8830 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 8831 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8832 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8833 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8834 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8835 | }; |
| 8836 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8837 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8838 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8839 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8840 | // Negotiate SPDY to the proxy |
| 8841 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8842 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8843 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8844 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8845 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8846 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8847 | TestCompletionCallback callback; |
| 8848 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8849 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8850 | |
| 8851 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8852 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8853 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8854 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8855 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8856 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8857 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8859 | |
| 8860 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8861 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8862 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8863 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8864 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8865 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8866 | |
| 8867 | EXPECT_EQ(200, response->headers->response_code()); |
| 8868 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8869 | |
| 8870 | std::string response_data; |
| 8871 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8872 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8873 | EXPECT_EQ("hello!", response_data); |
| 8874 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8875 | LoadTimingInfo load_timing_info; |
| 8876 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8877 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8878 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8879 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8880 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8881 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8882 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8883 | |
| 8884 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8885 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8886 | EXPECT_EQ("pushed", response_data); |
| 8887 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8888 | LoadTimingInfo push_load_timing_info; |
| 8889 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8890 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8891 | // The transactions should share a socket ID, despite being for different |
| 8892 | // origins. |
| 8893 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8894 | push_load_timing_info.socket_log_id); |
| 8895 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8896 | trans.reset(); |
| 8897 | push_trans.reset(); |
| 8898 | session->CloseAllConnections(); |
| 8899 | } |
| 8900 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8901 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8902 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8903 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8904 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8905 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8906 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8907 | HttpRequestInfo request; |
| 8908 | |
| 8909 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8910 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8911 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8912 | session_deps_.proxy_service = |
| 8913 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8914 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8915 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8916 | |
| 8917 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8918 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8919 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8920 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8921 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8922 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8923 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8924 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8925 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8926 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8927 | |
| 8928 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8929 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8930 | }; |
| 8931 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8932 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8933 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8934 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8935 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8936 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8937 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8938 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8939 | |
| 8940 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8941 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8942 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8943 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8944 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8945 | }; |
| 8946 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8947 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8948 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8949 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8950 | // Negotiate SPDY to the proxy |
| 8951 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8952 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8953 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8954 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8955 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8956 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8957 | TestCompletionCallback callback; |
| 8958 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8960 | |
| 8961 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8962 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8963 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8964 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8965 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8966 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8967 | |
| 8968 | EXPECT_EQ(200, response->headers->response_code()); |
| 8969 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8970 | |
| 8971 | std::string response_data; |
| 8972 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8973 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8974 | EXPECT_EQ("hello!", response_data); |
| 8975 | |
| 8976 | trans.reset(); |
| 8977 | session->CloseAllConnections(); |
| 8978 | } |
| 8979 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8980 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8981 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8982 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8983 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8984 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8985 | proxy_delegate->set_trusted_spdy_proxy( |
| 8986 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8987 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8988 | HttpRequestInfo request; |
| 8989 | |
| 8990 | request.method = "GET"; |
| 8991 | request.url = GURL("http://www.example.org/"); |
| 8992 | |
| 8993 | // Configure against https proxy server "myproxy:70". |
| 8994 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8995 | BoundTestNetLog log; |
| 8996 | session_deps_.net_log = log.bound().net_log(); |
| 8997 | |
| 8998 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8999 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9000 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9001 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9002 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9003 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9004 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9005 | SpdySerializedFrame stream2_priority( |
| 9006 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9007 | |
| 9008 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9009 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9010 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9011 | }; |
| 9012 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9013 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9014 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9015 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9016 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 9017 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 9018 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9019 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9020 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9021 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9022 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9023 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9024 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9025 | |
| 9026 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9027 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9028 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9029 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9030 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9031 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9032 | }; |
| 9033 | |
| 9034 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9035 | arraysize(spdy_writes)); |
| 9036 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 9037 | // Negotiate SPDY to the proxy |
| 9038 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9039 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9040 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 9041 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9042 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9043 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9044 | TestCompletionCallback callback; |
| 9045 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9047 | |
| 9048 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9049 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9050 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9051 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9052 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9053 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9054 | |
| 9055 | EXPECT_EQ(200, response->headers->response_code()); |
| 9056 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9057 | |
| 9058 | std::string response_data; |
| 9059 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9060 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9061 | EXPECT_EQ("hello!", response_data); |
| 9062 | |
| 9063 | trans.reset(); |
| 9064 | session->CloseAllConnections(); |
| 9065 | } |
| 9066 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9067 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 9068 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9069 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9070 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9071 | |
| 9072 | HttpRequestInfo request; |
| 9073 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9074 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9075 | |
| 9076 | // Attempt to fetch the URL from a server with a bad cert |
| 9077 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9078 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9079 | "Host: www.example.org:443\r\n" |
| 9080 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9081 | }; |
| 9082 | |
| 9083 | MockRead bad_cert_reads[] = { |
| 9084 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9085 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9086 | }; |
| 9087 | |
| 9088 | // Attempt to fetch the URL with a good cert |
| 9089 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9090 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9091 | "Host: www.example.org:443\r\n" |
| 9092 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9093 | MockWrite("GET / HTTP/1.1\r\n" |
| 9094 | "Host: www.example.org\r\n" |
| 9095 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9096 | }; |
| 9097 | |
| 9098 | MockRead good_cert_reads[] = { |
| 9099 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9100 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9101 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9102 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9103 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9104 | }; |
| 9105 | |
| 9106 | StaticSocketDataProvider ssl_bad_certificate( |
| 9107 | bad_cert_reads, arraysize(bad_cert_reads), |
| 9108 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 9109 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 9110 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9111 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9112 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9113 | |
| 9114 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9115 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9116 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9117 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9118 | |
| 9119 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9120 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9121 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9122 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9123 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9124 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9125 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9126 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9127 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9128 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9129 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9130 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9131 | |
| 9132 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9133 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9134 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9135 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9136 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9137 | |
| 9138 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9139 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9140 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9141 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9142 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9143 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9144 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9145 | } |
| 9146 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9147 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9148 | HttpRequestInfo request; |
| 9149 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9150 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9151 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9152 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9153 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9154 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9155 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9156 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9157 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9158 | MockWrite( |
| 9159 | "GET / HTTP/1.1\r\n" |
| 9160 | "Host: www.example.org\r\n" |
| 9161 | "Connection: keep-alive\r\n" |
| 9162 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9163 | }; |
| 9164 | |
| 9165 | // Lastly, the server responds with the actual content. |
| 9166 | MockRead data_reads[] = { |
| 9167 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9168 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9169 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9170 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9171 | }; |
| 9172 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9173 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9174 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9175 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9176 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9177 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9178 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9179 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9180 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9181 | |
| 9182 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9183 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9184 | } |
| 9185 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9186 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9187 | HttpRequestInfo request; |
| 9188 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9189 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9190 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9191 | "Chromium Ultra Awesome X Edition"); |
| 9192 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9193 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9194 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9195 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9196 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9197 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9198 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9199 | "Host: www.example.org:443\r\n" |
| 9200 | "Proxy-Connection: keep-alive\r\n" |
| 9201 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9202 | }; |
| 9203 | MockRead data_reads[] = { |
| 9204 | // Return an error, so the transaction stops here (this test isn't |
| 9205 | // interested in the rest). |
| 9206 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 9207 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9208 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 9209 | }; |
| 9210 | |
| 9211 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9212 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9213 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9214 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9215 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9216 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9217 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9218 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9219 | |
| 9220 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9221 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9222 | } |
| 9223 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9224 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9225 | HttpRequestInfo request; |
| 9226 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9227 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 9228 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 9229 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9230 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9231 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9232 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9233 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9234 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9235 | MockWrite( |
| 9236 | "GET / HTTP/1.1\r\n" |
| 9237 | "Host: www.example.org\r\n" |
| 9238 | "Connection: keep-alive\r\n" |
| 9239 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9240 | }; |
| 9241 | |
| 9242 | // Lastly, the server responds with the actual content. |
| 9243 | MockRead data_reads[] = { |
| 9244 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9245 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9246 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9247 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9248 | }; |
| 9249 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9250 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9251 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9252 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9253 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9254 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9255 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9256 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9257 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9258 | |
| 9259 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9260 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9261 | } |
| 9262 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9263 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9264 | HttpRequestInfo request; |
| 9265 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9266 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9267 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9268 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9269 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9270 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9271 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9272 | MockWrite( |
| 9273 | "POST / HTTP/1.1\r\n" |
| 9274 | "Host: www.example.org\r\n" |
| 9275 | "Connection: keep-alive\r\n" |
| 9276 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9277 | }; |
| 9278 | |
| 9279 | // Lastly, the server responds with the actual content. |
| 9280 | MockRead data_reads[] = { |
| 9281 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9282 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9283 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9284 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9285 | }; |
| 9286 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9287 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9288 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9289 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9291 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9292 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9293 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9294 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9295 | |
| 9296 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9297 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9298 | } |
| 9299 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9300 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9301 | HttpRequestInfo request; |
| 9302 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9303 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9304 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9306 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9307 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9308 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9309 | MockWrite( |
| 9310 | "PUT / HTTP/1.1\r\n" |
| 9311 | "Host: www.example.org\r\n" |
| 9312 | "Connection: keep-alive\r\n" |
| 9313 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9314 | }; |
| 9315 | |
| 9316 | // Lastly, the server responds with the actual content. |
| 9317 | MockRead data_reads[] = { |
| 9318 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9319 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9320 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9321 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9322 | }; |
| 9323 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9324 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9325 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9326 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9327 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9328 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9329 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9330 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9331 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9332 | |
| 9333 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9334 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9335 | } |
| 9336 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9337 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9338 | HttpRequestInfo request; |
| 9339 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9340 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9341 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9342 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9343 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9344 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9345 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 9346 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 9347 | "Host: www.example.org\r\n" |
| 9348 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9349 | }; |
| 9350 | |
| 9351 | // Lastly, the server responds with the actual content. |
| 9352 | MockRead data_reads[] = { |
| 9353 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9354 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9355 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9356 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9357 | }; |
| 9358 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9359 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9360 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9361 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9362 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9363 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9364 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9365 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9366 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9367 | |
| 9368 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9369 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9370 | } |
| 9371 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9372 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9373 | HttpRequestInfo request; |
| 9374 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9375 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9376 | request.load_flags = LOAD_BYPASS_CACHE; |
| 9377 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9378 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9379 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9380 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9381 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9382 | MockWrite( |
| 9383 | "GET / HTTP/1.1\r\n" |
| 9384 | "Host: www.example.org\r\n" |
| 9385 | "Connection: keep-alive\r\n" |
| 9386 | "Pragma: no-cache\r\n" |
| 9387 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9388 | }; |
| 9389 | |
| 9390 | // Lastly, the server responds with the actual content. |
| 9391 | MockRead data_reads[] = { |
| 9392 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9393 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9394 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9395 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9396 | }; |
| 9397 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9398 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9399 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9400 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9401 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9402 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9403 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9404 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9405 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9406 | |
| 9407 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9408 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9409 | } |
| 9410 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9411 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9412 | HttpRequestInfo request; |
| 9413 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9414 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9415 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 9416 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9417 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9418 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9419 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9420 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9421 | MockWrite( |
| 9422 | "GET / HTTP/1.1\r\n" |
| 9423 | "Host: www.example.org\r\n" |
| 9424 | "Connection: keep-alive\r\n" |
| 9425 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9426 | }; |
| 9427 | |
| 9428 | // Lastly, the server responds with the actual content. |
| 9429 | MockRead data_reads[] = { |
| 9430 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9431 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9432 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9433 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9434 | }; |
| 9435 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9436 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9437 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9438 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9440 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9441 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9442 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9443 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9444 | |
| 9445 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9446 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9447 | } |
| 9448 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9449 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9450 | HttpRequestInfo request; |
| 9451 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9452 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9453 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9454 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9455 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9456 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9457 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9458 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9459 | MockWrite( |
| 9460 | "GET / HTTP/1.1\r\n" |
| 9461 | "Host: www.example.org\r\n" |
| 9462 | "Connection: keep-alive\r\n" |
| 9463 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9464 | }; |
| 9465 | |
| 9466 | // Lastly, the server responds with the actual content. |
| 9467 | MockRead data_reads[] = { |
| 9468 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9469 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9470 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9471 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9472 | }; |
| 9473 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9474 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9475 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9476 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9477 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9478 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9479 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9480 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9482 | |
| 9483 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9484 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9485 | } |
| 9486 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9487 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9488 | HttpRequestInfo request; |
| 9489 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9490 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9491 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9492 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9493 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9494 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9495 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9496 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9497 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9498 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9499 | MockWrite( |
| 9500 | "GET / HTTP/1.1\r\n" |
| 9501 | "Host: www.example.org\r\n" |
| 9502 | "Connection: keep-alive\r\n" |
| 9503 | "referer: www.foo.com\r\n" |
| 9504 | "hEllo: Kitty\r\n" |
| 9505 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9506 | }; |
| 9507 | |
| 9508 | // Lastly, the server responds with the actual content. |
| 9509 | MockRead data_reads[] = { |
| 9510 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9511 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9512 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9513 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9514 | }; |
| 9515 | |
| 9516 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9517 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9518 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9519 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9520 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9521 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9522 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9523 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9524 | |
| 9525 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9526 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9527 | } |
| 9528 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9529 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9530 | HttpRequestInfo request; |
| 9531 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9532 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9533 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9534 | session_deps_.proxy_service = |
| 9535 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9536 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9537 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9538 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9539 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9540 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9541 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9542 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9543 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9544 | |
| 9545 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9546 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9547 | MockWrite( |
| 9548 | "GET / HTTP/1.1\r\n" |
| 9549 | "Host: www.example.org\r\n" |
| 9550 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9551 | |
| 9552 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9553 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9554 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9555 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9556 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9557 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9558 | }; |
| 9559 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9560 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9561 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9562 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9563 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9564 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9565 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9566 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9567 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9568 | |
| 9569 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9570 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9571 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9572 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9573 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9574 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9575 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9576 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9577 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9578 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9579 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9580 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9581 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9582 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9583 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9584 | EXPECT_EQ("Payload", response_text); |
| 9585 | } |
| 9586 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9587 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9588 | HttpRequestInfo request; |
| 9589 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9590 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9591 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9592 | session_deps_.proxy_service = |
| 9593 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9594 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9595 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9596 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9597 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9598 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9599 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9600 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9601 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9602 | |
| 9603 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9604 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9605 | arraysize(write_buffer)), |
| 9606 | MockWrite( |
| 9607 | "GET / HTTP/1.1\r\n" |
| 9608 | "Host: www.example.org\r\n" |
| 9609 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9610 | |
| 9611 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9612 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9613 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9614 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9615 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9616 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9617 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9618 | }; |
| 9619 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9620 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9621 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9622 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9623 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9624 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9625 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9626 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9627 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9628 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9629 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9630 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9631 | |
| 9632 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9633 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9634 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9635 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9636 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9637 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9638 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9640 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9641 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9642 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9643 | |
| 9644 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9645 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9646 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9647 | EXPECT_EQ("Payload", response_text); |
| 9648 | } |
| 9649 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9650 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9651 | HttpRequestInfo request; |
| 9652 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9653 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9654 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9655 | session_deps_.proxy_service = |
| 9656 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9657 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9658 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9659 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9660 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9661 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9662 | |
| 9663 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9664 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9665 | |
| 9666 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9667 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9668 | MockWrite( |
| 9669 | "GET / HTTP/1.1\r\n" |
| 9670 | "Host: www.example.org\r\n" |
| 9671 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9672 | |
| 9673 | MockRead data_reads[] = { |
| 9674 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9675 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9676 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9677 | MockRead("Payload"), |
| 9678 | MockRead(SYNCHRONOUS, OK) |
| 9679 | }; |
| 9680 | |
| 9681 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9682 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9683 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9684 | |
| 9685 | TestCompletionCallback callback; |
| 9686 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9687 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9688 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9689 | |
| 9690 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9691 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9692 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9693 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9694 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9695 | |
| 9696 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9697 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9698 | TestLoadTimingNotReused(load_timing_info, |
| 9699 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9700 | |
| 9701 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9702 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9703 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9704 | EXPECT_EQ("Payload", response_text); |
| 9705 | } |
| 9706 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9707 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9708 | HttpRequestInfo request; |
| 9709 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9710 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9711 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9712 | session_deps_.proxy_service = |
| 9713 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9714 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9715 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9716 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9717 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9718 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9719 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9720 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9721 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9722 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9723 | 0x05, // Version |
| 9724 | 0x01, // Command (CONNECT) |
| 9725 | 0x00, // Reserved. |
| 9726 | 0x03, // Address type (DOMAINNAME). |
| 9727 | 0x0F, // Length of domain (15) |
| 9728 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9729 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9730 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9731 | const char kSOCKS5OkResponse[] = |
| 9732 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9733 | |
| 9734 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9735 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9736 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9737 | MockWrite( |
| 9738 | "GET / HTTP/1.1\r\n" |
| 9739 | "Host: www.example.org\r\n" |
| 9740 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9741 | |
| 9742 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9743 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9744 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9745 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9746 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9747 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9748 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9749 | }; |
| 9750 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9751 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9752 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9753 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9754 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9755 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9756 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9757 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9758 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9759 | |
| 9760 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9761 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9762 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9763 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9764 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9765 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9766 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9767 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9768 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9769 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9770 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9771 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9772 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9773 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9774 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9775 | EXPECT_EQ("Payload", response_text); |
| 9776 | } |
| 9777 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9778 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9779 | HttpRequestInfo request; |
| 9780 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9781 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9782 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9783 | session_deps_.proxy_service = |
| 9784 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9785 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9786 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9787 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9788 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9789 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9790 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9791 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9792 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9793 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9794 | 0x05, // Version |
| 9795 | 0x01, // Command (CONNECT) |
| 9796 | 0x00, // Reserved. |
| 9797 | 0x03, // Address type (DOMAINNAME). |
| 9798 | 0x0F, // Length of domain (15) |
| 9799 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9800 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9801 | }; |
| 9802 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9803 | const char kSOCKS5OkResponse[] = |
| 9804 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9805 | |
| 9806 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9807 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9808 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9809 | arraysize(kSOCKS5OkRequest)), |
| 9810 | MockWrite( |
| 9811 | "GET / HTTP/1.1\r\n" |
| 9812 | "Host: www.example.org\r\n" |
| 9813 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9814 | |
| 9815 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9816 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9817 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9818 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9819 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9820 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9821 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9822 | }; |
| 9823 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9824 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9825 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9826 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9827 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9828 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9829 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9831 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9832 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9833 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9834 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9835 | |
| 9836 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9837 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9839 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9840 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9841 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9842 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9843 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9844 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9845 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9846 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9847 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9848 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9849 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9850 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9851 | EXPECT_EQ("Payload", response_text); |
| 9852 | } |
| 9853 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9854 | namespace { |
| 9855 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9856 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9857 | |
| 9858 | struct GroupNameTest { |
| 9859 | std::string proxy_server; |
| 9860 | std::string url; |
| 9861 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9862 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9863 | }; |
| 9864 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9865 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9866 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9867 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9868 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9869 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9870 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9871 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9872 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 9873 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9874 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9875 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9876 | |
| 9877 | return session; |
| 9878 | } |
| 9879 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9880 | int GroupNameTransactionHelper(const std::string& url, |
| 9881 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9882 | HttpRequestInfo request; |
| 9883 | request.method = "GET"; |
| 9884 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9885 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9886 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9888 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9889 | |
| 9890 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9891 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9892 | } |
| 9893 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9894 | } // namespace |
| 9895 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9896 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9897 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9898 | { |
| 9899 | "", // unused |
| 9900 | "http://www.example.org/direct", |
| 9901 | "www.example.org:80", |
| 9902 | false, |
| 9903 | }, |
| 9904 | { |
| 9905 | "", // unused |
| 9906 | "http://[2001:1418:13:1::25]/direct", |
| 9907 | "[2001:1418:13:1::25]:80", |
| 9908 | false, |
| 9909 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9910 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9911 | // SSL Tests |
| 9912 | { |
| 9913 | "", // unused |
| 9914 | "https://www.example.org/direct_ssl", |
| 9915 | "ssl/www.example.org:443", |
| 9916 | true, |
| 9917 | }, |
| 9918 | { |
| 9919 | "", // unused |
| 9920 | "https://[2001:1418:13:1::25]/direct", |
| 9921 | "ssl/[2001:1418:13:1::25]:443", |
| 9922 | true, |
| 9923 | }, |
| 9924 | { |
| 9925 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9926 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9927 | "ssl/host.with.alternate:443", |
| 9928 | true, |
| 9929 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9930 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9931 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9932 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9933 | session_deps_.proxy_service = |
| 9934 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9935 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9936 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9937 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9938 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9939 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9940 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9941 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9942 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9943 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9944 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9945 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9946 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9947 | |
| 9948 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9949 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame^] | 9950 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9951 | EXPECT_EQ(tests[i].expected_group_name, |
| 9952 | ssl_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame^] | 9953 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9954 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9955 | transport_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame^] | 9956 | } |
| 9957 | // When SSL proxy is in use, socket must be requested from |ssl_conn_pool|. |
| 9958 | EXPECT_EQ(tests[i].ssl, ssl_conn_pool->socket_requested()); |
| 9959 | // When SSL proxy is not in use, socket must be requested from |
| 9960 | // |transport_conn_pool|. |
| 9961 | EXPECT_EQ(!tests[i].ssl, transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9962 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9963 | } |
| 9964 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9965 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9966 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9967 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 9968 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 9969 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9970 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9971 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9972 | // SSL Tests |
| 9973 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 9974 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 9975 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9976 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9977 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9978 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 9979 | "http_proxy", "https://host.with.alternate/direct", |
| 9980 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9981 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9982 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9983 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 9984 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 9985 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9986 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9987 | }; |
| 9988 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9989 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9990 | session_deps_.proxy_service = |
| 9991 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9992 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9993 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9994 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9995 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9996 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9997 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9998 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9999 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10000 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10001 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10002 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10003 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 10004 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 10005 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10006 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10007 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10008 | |
| 10009 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10010 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10011 | if (tests[i].ssl) |
| 10012 | EXPECT_EQ(tests[i].expected_group_name, |
| 10013 | ssl_conn_pool->last_group_name_received()); |
| 10014 | else |
| 10015 | EXPECT_EQ(tests[i].expected_group_name, |
| 10016 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10017 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10018 | } |
| 10019 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10020 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10021 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10022 | { |
| 10023 | "socks4://socks_proxy:1080", |
| 10024 | "http://www.example.org/socks4_direct", |
| 10025 | "socks4/www.example.org:80", |
| 10026 | false, |
| 10027 | }, |
| 10028 | { |
| 10029 | "socks5://socks_proxy:1080", |
| 10030 | "http://www.example.org/socks5_direct", |
| 10031 | "socks5/www.example.org:80", |
| 10032 | false, |
| 10033 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10034 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10035 | // SSL Tests |
| 10036 | { |
| 10037 | "socks4://socks_proxy:1080", |
| 10038 | "https://www.example.org/socks4_ssl", |
| 10039 | "socks4/ssl/www.example.org:443", |
| 10040 | true, |
| 10041 | }, |
| 10042 | { |
| 10043 | "socks5://socks_proxy:1080", |
| 10044 | "https://www.example.org/socks5_ssl", |
| 10045 | "socks5/ssl/www.example.org:443", |
| 10046 | true, |
| 10047 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10048 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10049 | { |
| 10050 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10051 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10052 | "socks4/ssl/host.with.alternate:443", |
| 10053 | true, |
| 10054 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10055 | }; |
| 10056 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10057 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 10058 | session_deps_.proxy_service = |
| 10059 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10060 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10061 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 10062 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10063 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10064 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10065 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10066 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10067 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10068 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10069 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10070 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10071 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 10072 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 10073 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10074 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10075 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10076 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10077 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10078 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10079 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10080 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10081 | if (tests[i].ssl) |
| 10082 | EXPECT_EQ(tests[i].expected_group_name, |
| 10083 | ssl_conn_pool->last_group_name_received()); |
| 10084 | else |
| 10085 | EXPECT_EQ(tests[i].expected_group_name, |
| 10086 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10087 | } |
| 10088 | } |
| 10089 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10090 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10091 | HttpRequestInfo request; |
| 10092 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10093 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10094 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 10095 | session_deps_.proxy_service = |
| 10096 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10097 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 10098 | // This simulates failure resolving all hostnames; that means we will fail |
| 10099 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10100 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10101 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10102 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10103 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10104 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10105 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10106 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10107 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10108 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10109 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10110 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10111 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10112 | } |
| 10113 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10114 | // Base test to make sure that when the load flags for a request specify to |
| 10115 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10116 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10117 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10118 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10119 | HttpRequestInfo request_info; |
| 10120 | request_info.method = "GET"; |
| 10121 | request_info.load_flags = load_flags; |
| 10122 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10123 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 10124 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10125 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10126 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10127 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10128 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10129 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10130 | // 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] | 10131 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10132 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10133 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10134 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10135 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10136 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10137 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10138 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10139 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10140 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10141 | |
| 10142 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 10143 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10144 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10145 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10146 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10147 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10148 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10149 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10150 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10151 | // 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] | 10152 | // we can tell if the next lookup hit the cache, or the "network". |
| 10153 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10154 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10155 | |
| 10156 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 10157 | // 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] | 10158 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10159 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10160 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10161 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10162 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10163 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10164 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10165 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10166 | |
| 10167 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10168 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10169 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10170 | } |
| 10171 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10172 | // There are multiple load flags that should trigger the host cache bypass. |
| 10173 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10174 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10175 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 10176 | } |
| 10177 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10178 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10179 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 10180 | } |
| 10181 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10182 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10183 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 10184 | } |
| 10185 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10186 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10187 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10188 | HttpRequestInfo request; |
| 10189 | request.method = "GET"; |
| 10190 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10191 | |
| 10192 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10193 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10194 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10195 | StaticSocketDataProvider data(NULL, 0, |
| 10196 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10197 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10198 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10200 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10201 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10202 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10203 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10204 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10205 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10206 | |
| 10207 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10208 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10209 | |
| 10210 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10211 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10212 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10213 | } |
| 10214 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10215 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10216 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10217 | HttpRequestInfo request; |
| 10218 | request.method = "GET"; |
| 10219 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10220 | |
| 10221 | MockRead data_reads[] = { |
| 10222 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10223 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10224 | }; |
| 10225 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10226 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10227 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10228 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10229 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10230 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10232 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10233 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10234 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10235 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10236 | |
| 10237 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10238 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10240 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10241 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10242 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10243 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10244 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10245 | |
| 10246 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10247 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10248 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10249 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10250 | |
| 10251 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10252 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10253 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10254 | } |
| 10255 | |
| 10256 | // Make sure that a dropped connection while draining the body for auth |
| 10257 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10258 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10259 | HttpRequestInfo request; |
| 10260 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10261 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10262 | |
| 10263 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10264 | MockWrite( |
| 10265 | "GET / HTTP/1.1\r\n" |
| 10266 | "Host: www.example.org\r\n" |
| 10267 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10268 | }; |
| 10269 | |
| 10270 | MockRead data_reads1[] = { |
| 10271 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 10272 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10273 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10274 | MockRead("Content-Length: 14\r\n\r\n"), |
| 10275 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10276 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10277 | }; |
| 10278 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10279 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10280 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10281 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10282 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10283 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10284 | // be issuing -- the final header line contains the credentials. |
| 10285 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10286 | MockWrite( |
| 10287 | "GET / HTTP/1.1\r\n" |
| 10288 | "Host: www.example.org\r\n" |
| 10289 | "Connection: keep-alive\r\n" |
| 10290 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10291 | }; |
| 10292 | |
| 10293 | // Lastly, the server responds with the actual content. |
| 10294 | MockRead data_reads2[] = { |
| 10295 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10296 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10297 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10298 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10299 | }; |
| 10300 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10301 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10302 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10303 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10304 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10305 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10306 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10307 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10308 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10309 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10310 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10311 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10312 | |
| 10313 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10314 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10315 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10316 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10317 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10318 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10319 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10320 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10321 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10322 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10323 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10324 | |
| 10325 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10326 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10327 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10328 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10329 | ASSERT_TRUE(response); |
| 10330 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10331 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10332 | } |
| 10333 | |
| 10334 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10335 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 10336 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10337 | |
| 10338 | HttpRequestInfo request; |
| 10339 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10340 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10341 | |
| 10342 | MockRead proxy_reads[] = { |
| 10343 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10344 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10345 | }; |
| 10346 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10347 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10348 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10349 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10350 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10351 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10352 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10353 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10354 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10355 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10356 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10357 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10358 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10359 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10360 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10361 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10362 | |
| 10363 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10364 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10365 | } |
| 10366 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10367 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10368 | HttpRequestInfo request; |
| 10369 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10370 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10371 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10372 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10373 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10374 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10375 | MockRead data_reads[] = { |
| 10376 | 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] | 10377 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10378 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10379 | |
| 10380 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10381 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10382 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10383 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10384 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10385 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10386 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10387 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10388 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10389 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10390 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10391 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10392 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10393 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10394 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10395 | |
| 10396 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10397 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10398 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10399 | } |
| 10400 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10401 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10402 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10403 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10404 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10405 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10406 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10407 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10408 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10409 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10410 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10411 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10412 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10413 | |
| 10414 | HttpRequestInfo request; |
| 10415 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10416 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10417 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10418 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10419 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10420 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10421 | |
| 10422 | MockRead data_reads[] = { |
| 10423 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10424 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10425 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10426 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10427 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10428 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10429 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10430 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10431 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10432 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10433 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10434 | |
| 10435 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10436 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10438 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10439 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10440 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10441 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10442 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10443 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10444 | } |
| 10445 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10446 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10447 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10448 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10449 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10450 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10451 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10452 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10453 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10454 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10455 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10456 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10457 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10458 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10459 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10460 | |
| 10461 | HttpRequestInfo request; |
| 10462 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10463 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10464 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10465 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10466 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10467 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10468 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10469 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10470 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10471 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10473 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10474 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10475 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10476 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10477 | |
| 10478 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10479 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10480 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10481 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10482 | } |
| 10483 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10484 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10485 | class FakeUploadElementReader : public UploadElementReader { |
| 10486 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 10487 | FakeUploadElementReader() = default; |
| 10488 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10489 | |
| 10490 | const CompletionCallback& callback() const { return callback_; } |
| 10491 | |
| 10492 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10493 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10494 | callback_ = callback; |
| 10495 | return ERR_IO_PENDING; |
| 10496 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10497 | uint64_t GetContentLength() const override { return 0; } |
| 10498 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10499 | int Read(IOBuffer* buf, |
| 10500 | int buf_length, |
| 10501 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10502 | return ERR_FAILED; |
| 10503 | } |
| 10504 | |
| 10505 | private: |
| 10506 | CompletionCallback callback_; |
| 10507 | }; |
| 10508 | |
| 10509 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10510 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10511 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10512 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10513 | |
| 10514 | HttpRequestInfo request; |
| 10515 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10516 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10517 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10518 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10519 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10520 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10521 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10522 | |
| 10523 | StaticSocketDataProvider data; |
| 10524 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10525 | |
| 10526 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10527 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10528 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10529 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10530 | |
| 10531 | // Transaction is pending on request body initialization. |
| 10532 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 10533 | |
| 10534 | // Return Init()'s result after the transaction gets destroyed. |
| 10535 | trans.reset(); |
| 10536 | fake_reader->callback().Run(OK); // Should not crash. |
| 10537 | } |
| 10538 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10539 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10540 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10541 | HttpRequestInfo request; |
| 10542 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10543 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10544 | |
| 10545 | // First transaction will request a resource and receive a Basic challenge |
| 10546 | // with realm="first_realm". |
| 10547 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10548 | MockWrite( |
| 10549 | "GET / HTTP/1.1\r\n" |
| 10550 | "Host: www.example.org\r\n" |
| 10551 | "Connection: keep-alive\r\n" |
| 10552 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10553 | }; |
| 10554 | MockRead data_reads1[] = { |
| 10555 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10556 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10557 | "\r\n"), |
| 10558 | }; |
| 10559 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10560 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10561 | // for first_realm. The server will reject and provide a challenge with |
| 10562 | // second_realm. |
| 10563 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10564 | MockWrite( |
| 10565 | "GET / HTTP/1.1\r\n" |
| 10566 | "Host: www.example.org\r\n" |
| 10567 | "Connection: keep-alive\r\n" |
| 10568 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10569 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10570 | }; |
| 10571 | MockRead data_reads2[] = { |
| 10572 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10573 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10574 | "\r\n"), |
| 10575 | }; |
| 10576 | |
| 10577 | // This again fails, and goes back to first_realm. Make sure that the |
| 10578 | // entry is removed from cache. |
| 10579 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10580 | MockWrite( |
| 10581 | "GET / HTTP/1.1\r\n" |
| 10582 | "Host: www.example.org\r\n" |
| 10583 | "Connection: keep-alive\r\n" |
| 10584 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10585 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10586 | }; |
| 10587 | MockRead data_reads3[] = { |
| 10588 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10589 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10590 | "\r\n"), |
| 10591 | }; |
| 10592 | |
| 10593 | // Try one last time (with the correct password) and get the resource. |
| 10594 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10595 | MockWrite( |
| 10596 | "GET / HTTP/1.1\r\n" |
| 10597 | "Host: www.example.org\r\n" |
| 10598 | "Connection: keep-alive\r\n" |
| 10599 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10600 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10601 | }; |
| 10602 | MockRead data_reads4[] = { |
| 10603 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10604 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10605 | "Content-Length: 5\r\n" |
| 10606 | "\r\n" |
| 10607 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10608 | }; |
| 10609 | |
| 10610 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10611 | data_writes1, arraysize(data_writes1)); |
| 10612 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10613 | data_writes2, arraysize(data_writes2)); |
| 10614 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 10615 | data_writes3, arraysize(data_writes3)); |
| 10616 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 10617 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10618 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10619 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10620 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10621 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10622 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10623 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10624 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10625 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10627 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10628 | // Issue the first request with Authorize headers. There should be a |
| 10629 | // password prompt for first_realm waiting to be filled in after the |
| 10630 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10631 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10632 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10633 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10634 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10635 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10636 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10637 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10638 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10639 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10640 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10641 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10642 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10643 | |
| 10644 | // Issue the second request with an incorrect password. There should be a |
| 10645 | // password prompt for second_realm waiting to be filled in after the |
| 10646 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10647 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10648 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10649 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10650 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10651 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10652 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10653 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10654 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10655 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10656 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10657 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10658 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10659 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10660 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10661 | |
| 10662 | // Issue the third request with another incorrect password. There should be |
| 10663 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10664 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10665 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10666 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10667 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10668 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10669 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10670 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10671 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10672 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10673 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10674 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10675 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10676 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10677 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10678 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10679 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10680 | |
| 10681 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10682 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10683 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10684 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10685 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10686 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10687 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10688 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10689 | ASSERT_TRUE(response); |
| 10690 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10691 | } |
| 10692 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10693 | // Regression test for https://crbug.com/754395. |
| 10694 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 10695 | MockRead data_reads[] = { |
| 10696 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10697 | MockRead(kAlternativeServiceHttpHeader), |
| 10698 | MockRead("\r\n"), |
| 10699 | MockRead("hello world"), |
| 10700 | MockRead(SYNCHRONOUS, OK), |
| 10701 | }; |
| 10702 | |
| 10703 | HttpRequestInfo request; |
| 10704 | request.method = "GET"; |
| 10705 | request.url = GURL("https://www.example.org/"); |
| 10706 | |
| 10707 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10708 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10709 | |
| 10710 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10711 | ssl.ssl_info.cert = |
| 10712 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10713 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 10714 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10715 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10716 | |
| 10717 | TestCompletionCallback callback; |
| 10718 | |
| 10719 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10720 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10721 | |
| 10722 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10723 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10724 | |
| 10725 | url::SchemeHostPort test_server(request.url); |
| 10726 | HttpServerProperties* http_server_properties = |
| 10727 | session->http_server_properties(); |
| 10728 | EXPECT_TRUE( |
| 10729 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10730 | |
| 10731 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 10732 | |
| 10733 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10734 | ASSERT_TRUE(response); |
| 10735 | ASSERT_TRUE(response->headers); |
| 10736 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10737 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10738 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 10739 | |
| 10740 | std::string response_data; |
| 10741 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 10742 | EXPECT_EQ("hello world", response_data); |
| 10743 | |
| 10744 | EXPECT_TRUE( |
| 10745 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10746 | } |
| 10747 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10748 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10749 | MockRead data_reads[] = { |
| 10750 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10751 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10752 | MockRead("\r\n"), |
| 10753 | MockRead("hello world"), |
| 10754 | MockRead(SYNCHRONOUS, OK), |
| 10755 | }; |
| 10756 | |
| 10757 | HttpRequestInfo request; |
| 10758 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10759 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10760 | |
| 10761 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10762 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10763 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10764 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10765 | ssl.ssl_info.cert = |
| 10766 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10767 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10768 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10769 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10770 | TestCompletionCallback callback; |
| 10771 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10772 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10773 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10774 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10775 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10776 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10777 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10778 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10779 | HttpServerProperties* http_server_properties = |
| 10780 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10781 | EXPECT_TRUE( |
| 10782 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10783 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10784 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10785 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10786 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10787 | ASSERT_TRUE(response); |
| 10788 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10789 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10790 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10791 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10792 | |
| 10793 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10794 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10795 | EXPECT_EQ("hello world", response_data); |
| 10796 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10797 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10798 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10799 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10800 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 10801 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10802 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10803 | } |
| 10804 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10805 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10806 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10807 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10808 | MockRead data_reads[] = { |
| 10809 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10810 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10811 | MockRead("\r\n"), |
| 10812 | MockRead("hello world"), |
| 10813 | MockRead(SYNCHRONOUS, OK), |
| 10814 | }; |
| 10815 | |
| 10816 | HttpRequestInfo request; |
| 10817 | request.method = "GET"; |
| 10818 | request.url = GURL("http://www.example.org/"); |
| 10819 | request.load_flags = 0; |
| 10820 | |
| 10821 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10822 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10823 | |
| 10824 | TestCompletionCallback callback; |
| 10825 | |
| 10826 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10827 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10828 | |
| 10829 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10830 | HttpServerProperties* http_server_properties = |
| 10831 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10832 | EXPECT_TRUE( |
| 10833 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10834 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10835 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10837 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10839 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10840 | ASSERT_TRUE(response); |
| 10841 | ASSERT_TRUE(response->headers); |
| 10842 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10843 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10844 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10845 | |
| 10846 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10847 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10848 | EXPECT_EQ("hello world", response_data); |
| 10849 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10850 | EXPECT_TRUE( |
| 10851 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10852 | } |
| 10853 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10854 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10855 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10856 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10857 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10858 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10859 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10860 | HttpRequestInfo request; |
| 10861 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10862 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10863 | request.load_flags = 0; |
| 10864 | |
| 10865 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10866 | StaticSocketDataProvider first_data; |
| 10867 | first_data.set_connect_data(mock_connect); |
| 10868 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10869 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10870 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10871 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10872 | |
| 10873 | MockRead data_reads[] = { |
| 10874 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10875 | MockRead(ASYNC, OK), |
| 10876 | }; |
| 10877 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10878 | 0); |
| 10879 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10880 | |
| 10881 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10882 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10883 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10884 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10885 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10886 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10887 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10888 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10889 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10890 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10891 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10892 | TestCompletionCallback callback; |
| 10893 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10894 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10895 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10896 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10897 | } |
| 10898 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10899 | // Regression test for https://crbug.com/615497: |
| 10900 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10901 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10902 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10903 | HttpRequestInfo request; |
| 10904 | request.method = "GET"; |
| 10905 | request.url = GURL("http://www.example.org/"); |
| 10906 | request.load_flags = 0; |
| 10907 | |
| 10908 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10909 | StaticSocketDataProvider first_data; |
| 10910 | first_data.set_connect_data(mock_connect); |
| 10911 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10912 | |
| 10913 | MockRead data_reads[] = { |
| 10914 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10915 | MockRead(ASYNC, OK), |
| 10916 | }; |
| 10917 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10918 | 0); |
| 10919 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10920 | |
| 10921 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10922 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10923 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10924 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10925 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10926 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10927 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10928 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10929 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10930 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10931 | TestCompletionCallback callback; |
| 10932 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10933 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10934 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10935 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10936 | } |
| 10937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10938 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10939 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10940 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10941 | HttpServerProperties* http_server_properties = |
| 10942 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10943 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10944 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10945 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10946 | http_server_properties->SetQuicAlternativeService( |
| 10947 | test_server, alternative_service, expiration, |
| 10948 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10949 | EXPECT_EQ( |
| 10950 | 1u, |
| 10951 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10952 | |
| 10953 | // Send a clear header. |
| 10954 | MockRead data_reads[] = { |
| 10955 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10956 | MockRead("Alt-Svc: clear\r\n"), |
| 10957 | MockRead("\r\n"), |
| 10958 | MockRead("hello world"), |
| 10959 | MockRead(SYNCHRONOUS, OK), |
| 10960 | }; |
| 10961 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10962 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10963 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10964 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10965 | ssl.ssl_info.cert = |
| 10966 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10967 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10968 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10969 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10970 | HttpRequestInfo request; |
| 10971 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10972 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10973 | |
| 10974 | TestCompletionCallback callback; |
| 10975 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10976 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10977 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10978 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10979 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10980 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10981 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10982 | ASSERT_TRUE(response); |
| 10983 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10984 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10985 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10986 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10987 | |
| 10988 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10989 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10990 | EXPECT_EQ("hello world", response_data); |
| 10991 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10992 | EXPECT_TRUE( |
| 10993 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10994 | } |
| 10995 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10996 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10997 | MockRead data_reads[] = { |
| 10998 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10999 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 11000 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11001 | MockRead("hello world"), |
| 11002 | MockRead(SYNCHRONOUS, OK), |
| 11003 | }; |
| 11004 | |
| 11005 | HttpRequestInfo request; |
| 11006 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11007 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11008 | |
| 11009 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11010 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11011 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11012 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11013 | ssl.ssl_info.cert = |
| 11014 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11015 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11016 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11017 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11018 | TestCompletionCallback callback; |
| 11019 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11020 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11021 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11022 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11023 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11024 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11025 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11026 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11027 | HttpServerProperties* http_server_properties = |
| 11028 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11029 | EXPECT_TRUE( |
| 11030 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11031 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11032 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11033 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11034 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11035 | ASSERT_TRUE(response); |
| 11036 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11037 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11038 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11039 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11040 | |
| 11041 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11042 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11043 | EXPECT_EQ("hello world", response_data); |
| 11044 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11045 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11046 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11047 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 11048 | |
| 11049 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 11050 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11051 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11052 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 11053 | 1234); |
| 11054 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11055 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11056 | } |
| 11057 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11058 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11059 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11060 | HostPortPair alternative("alternative.example.org", 443); |
| 11061 | std::string origin_url = "https://origin.example.org:443"; |
| 11062 | std::string alternative_url = "https://alternative.example.org:443"; |
| 11063 | |
| 11064 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 11065 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11066 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11067 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11068 | |
| 11069 | // HTTP/1.1 data for request. |
| 11070 | MockWrite http_writes[] = { |
| 11071 | MockWrite("GET / HTTP/1.1\r\n" |
| 11072 | "Host: alternative.example.org\r\n" |
| 11073 | "Connection: keep-alive\r\n\r\n"), |
| 11074 | }; |
| 11075 | |
| 11076 | MockRead http_reads[] = { |
| 11077 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11078 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11079 | "Content-Length: 40\r\n\r\n" |
| 11080 | "first HTTP/1.1 response from alternative"), |
| 11081 | }; |
| 11082 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11083 | http_writes, arraysize(http_writes)); |
| 11084 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11085 | |
| 11086 | StaticSocketDataProvider data_refused; |
| 11087 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11088 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11089 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11090 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11091 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11092 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11093 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11094 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11095 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11096 | http_server_properties->SetQuicAlternativeService( |
| 11097 | server, alternative_service, expiration, |
| 11098 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11099 | // Mark the QUIC alternative service as broken. |
| 11100 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 11101 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11102 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11103 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11104 | request.method = "GET"; |
| 11105 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11106 | TestCompletionCallback callback; |
| 11107 | NetErrorDetails details; |
| 11108 | EXPECT_FALSE(details.quic_broken); |
| 11109 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11110 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11111 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11112 | EXPECT_TRUE(details.quic_broken); |
| 11113 | } |
| 11114 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11115 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11116 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11117 | HostPortPair alternative1("alternative1.example.org", 443); |
| 11118 | HostPortPair alternative2("alternative2.example.org", 443); |
| 11119 | std::string origin_url = "https://origin.example.org:443"; |
| 11120 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 11121 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 11122 | |
| 11123 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 11124 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11125 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11126 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11127 | |
| 11128 | // HTTP/1.1 data for request. |
| 11129 | MockWrite http_writes[] = { |
| 11130 | MockWrite("GET / HTTP/1.1\r\n" |
| 11131 | "Host: alternative1.example.org\r\n" |
| 11132 | "Connection: keep-alive\r\n\r\n"), |
| 11133 | }; |
| 11134 | |
| 11135 | MockRead http_reads[] = { |
| 11136 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11137 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11138 | "Content-Length: 40\r\n\r\n" |
| 11139 | "first HTTP/1.1 response from alternative1"), |
| 11140 | }; |
| 11141 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11142 | http_writes, arraysize(http_writes)); |
| 11143 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11144 | |
| 11145 | StaticSocketDataProvider data_refused; |
| 11146 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11147 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11148 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11149 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11150 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11151 | session->http_server_properties(); |
| 11152 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11153 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11154 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 11155 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11156 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11157 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11158 | alternative_service_info_vector.push_back( |
| 11159 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11160 | alternative_service1, expiration, |
| 11161 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11162 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11163 | alternative_service_info_vector.push_back( |
| 11164 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11165 | alternative_service2, expiration, |
| 11166 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11167 | |
| 11168 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11169 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11170 | |
| 11171 | // Mark one of the QUIC alternative service as broken. |
| 11172 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11173 | EXPECT_EQ(2u, |
| 11174 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11175 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11176 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11177 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11178 | request.method = "GET"; |
| 11179 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11180 | TestCompletionCallback callback; |
| 11181 | NetErrorDetails details; |
| 11182 | EXPECT_FALSE(details.quic_broken); |
| 11183 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11184 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11185 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11186 | EXPECT_FALSE(details.quic_broken); |
| 11187 | } |
| 11188 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11189 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11190 | HttpRequestInfo request; |
| 11191 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11192 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11193 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11194 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11195 | StaticSocketDataProvider first_data; |
| 11196 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11197 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11198 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11199 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11200 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11201 | |
| 11202 | MockRead data_reads[] = { |
| 11203 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11204 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11205 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11206 | }; |
| 11207 | StaticSocketDataProvider second_data( |
| 11208 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11209 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11210 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11211 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11212 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11213 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11214 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11215 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11216 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 11217 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11218 | // Port is ignored by MockConnect anyway. |
| 11219 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11220 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11221 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11222 | http_server_properties->SetHttp2AlternativeService( |
| 11223 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11224 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11225 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11226 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11227 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11228 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11229 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11230 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11232 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11233 | ASSERT_TRUE(response); |
| 11234 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11235 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11236 | |
| 11237 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11238 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11239 | EXPECT_EQ("hello world", response_data); |
| 11240 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11241 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 11242 | http_server_properties->GetAlternativeServiceInfos(server); |
| 11243 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11244 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11245 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11246 | EXPECT_TRUE( |
| 11247 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11248 | } |
| 11249 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11250 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11251 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11252 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11253 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11254 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11255 | HttpRequestInfo restricted_port_request; |
| 11256 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11257 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11258 | restricted_port_request.load_flags = 0; |
| 11259 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11260 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11261 | StaticSocketDataProvider first_data; |
| 11262 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11263 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11264 | |
| 11265 | MockRead data_reads[] = { |
| 11266 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11267 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11268 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11269 | }; |
| 11270 | StaticSocketDataProvider second_data( |
| 11271 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11272 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11273 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11274 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11276 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11277 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11278 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11279 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11280 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11281 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11282 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11283 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11284 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11285 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11286 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11287 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11288 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11289 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11290 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11291 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11292 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11293 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11294 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11295 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11296 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11297 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11298 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11299 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 11300 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 11301 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11302 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11303 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11304 | |
| 11305 | HttpRequestInfo restricted_port_request; |
| 11306 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11307 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11308 | restricted_port_request.load_flags = 0; |
| 11309 | |
| 11310 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11311 | StaticSocketDataProvider first_data; |
| 11312 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11313 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11314 | |
| 11315 | MockRead data_reads[] = { |
| 11316 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11317 | MockRead("hello world"), |
| 11318 | MockRead(ASYNC, OK), |
| 11319 | }; |
| 11320 | StaticSocketDataProvider second_data( |
| 11321 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11322 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11323 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11324 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11325 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11326 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11327 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11328 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11329 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11330 | session->http_server_properties(); |
| 11331 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11332 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11333 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11334 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11335 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11336 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11337 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11338 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11339 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11340 | TestCompletionCallback callback; |
| 11341 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11342 | EXPECT_EQ(ERR_IO_PENDING, |
| 11343 | trans.Start(&restricted_port_request, callback.callback(), |
| 11344 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11345 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11346 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11347 | } |
| 11348 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11349 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11350 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11351 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11352 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11353 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11354 | HttpRequestInfo restricted_port_request; |
| 11355 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11356 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11357 | restricted_port_request.load_flags = 0; |
| 11358 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11359 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11360 | StaticSocketDataProvider first_data; |
| 11361 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11362 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11363 | |
| 11364 | MockRead data_reads[] = { |
| 11365 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11366 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11367 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11368 | }; |
| 11369 | StaticSocketDataProvider second_data( |
| 11370 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11371 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11372 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11373 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11375 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11376 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11377 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11378 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11379 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11380 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11381 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11382 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11383 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11384 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11385 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11386 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11387 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11388 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11389 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11390 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11391 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11392 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11394 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11395 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11396 | } |
| 11397 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11398 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11399 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11400 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11401 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11402 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11403 | HttpRequestInfo unrestricted_port_request; |
| 11404 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11405 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11406 | unrestricted_port_request.load_flags = 0; |
| 11407 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11408 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11409 | StaticSocketDataProvider first_data; |
| 11410 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11411 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11412 | |
| 11413 | MockRead data_reads[] = { |
| 11414 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11415 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11416 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11417 | }; |
| 11418 | StaticSocketDataProvider second_data( |
| 11419 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11420 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11421 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11422 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11424 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11425 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11426 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11427 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11428 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11429 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11430 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11431 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11432 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11433 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11434 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11435 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11436 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11437 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11438 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11439 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11440 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11441 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11442 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11443 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11444 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11445 | } |
| 11446 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11447 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11448 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11449 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11450 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11451 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11452 | HttpRequestInfo unrestricted_port_request; |
| 11453 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11454 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11455 | unrestricted_port_request.load_flags = 0; |
| 11456 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11457 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11458 | StaticSocketDataProvider first_data; |
| 11459 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11460 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11461 | |
| 11462 | MockRead data_reads[] = { |
| 11463 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11464 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11465 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11466 | }; |
| 11467 | StaticSocketDataProvider second_data( |
| 11468 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11469 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11470 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11471 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11472 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11473 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11474 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11475 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11476 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11477 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11478 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11479 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11480 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11481 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11482 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11483 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11484 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11485 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11486 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11487 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11488 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11489 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11490 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11491 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11492 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11493 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11494 | } |
| 11495 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11496 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11497 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 11498 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11499 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11500 | HttpRequestInfo request; |
| 11501 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11502 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11503 | |
| 11504 | // The alternate protocol request will error out before we attempt to connect, |
| 11505 | // so only the standard HTTP request will try to connect. |
| 11506 | MockRead data_reads[] = { |
| 11507 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11508 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11509 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11510 | }; |
| 11511 | StaticSocketDataProvider data( |
| 11512 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11513 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11514 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11516 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11517 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11518 | session->http_server_properties(); |
| 11519 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11520 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11521 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11522 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11523 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11524 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11525 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11526 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11527 | TestCompletionCallback callback; |
| 11528 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11529 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11530 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11531 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11532 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11534 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11535 | ASSERT_TRUE(response); |
| 11536 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11537 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11538 | |
| 11539 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11540 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11541 | EXPECT_EQ("hello world", response_data); |
| 11542 | } |
| 11543 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11544 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11545 | HttpRequestInfo request; |
| 11546 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11547 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11548 | |
| 11549 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11550 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11551 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11552 | MockRead("\r\n"), |
| 11553 | MockRead("hello world"), |
| 11554 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11555 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11556 | |
| 11557 | StaticSocketDataProvider first_transaction( |
| 11558 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11559 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11560 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11561 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11562 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11563 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11564 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11565 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11566 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11567 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11568 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11569 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11570 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11571 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11572 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11573 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11574 | }; |
| 11575 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11576 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11577 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11578 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11579 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11580 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11581 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11582 | NULL, 0, NULL, 0); |
| 11583 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11584 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11585 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11586 | &hanging_non_alternate_protocol_socket); |
| 11587 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11588 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11589 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11590 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11591 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11592 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11593 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11594 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11595 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11596 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11597 | |
| 11598 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11599 | ASSERT_TRUE(response); |
| 11600 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11601 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11602 | |
| 11603 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11604 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11605 | EXPECT_EQ("hello world", response_data); |
| 11606 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11607 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11608 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11609 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11610 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11611 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11612 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11613 | |
| 11614 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11615 | ASSERT_TRUE(response); |
| 11616 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11617 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11618 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11619 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11620 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11621 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11622 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11623 | } |
| 11624 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11625 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11626 | HttpRequestInfo request; |
| 11627 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11628 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11629 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11630 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11631 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11632 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11633 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11634 | MockRead("\r\n"), |
| 11635 | MockRead("hello world"), |
| 11636 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11637 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11638 | }; |
| 11639 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11640 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 11641 | 0); |
| 11642 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11643 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11644 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11645 | ssl_http11.ssl_info.cert = |
| 11646 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11647 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11648 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11649 | |
| 11650 | // Second transaction starts an alternative and a non-alternative Job. |
| 11651 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11652 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11653 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 11654 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11655 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11656 | |
| 11657 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 11658 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11659 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11660 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11661 | // Third transaction starts an alternative and a non-alternative job. |
| 11662 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11663 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11664 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11665 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11666 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11667 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11668 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11669 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11670 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11671 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11672 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11673 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11674 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11675 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11676 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 11677 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11678 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11679 | }; |
| 11680 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11681 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11682 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11683 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11684 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11685 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11686 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11687 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 11688 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 11689 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11690 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11691 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11692 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11693 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11694 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11695 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11697 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11698 | |
| 11699 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11700 | ASSERT_TRUE(response); |
| 11701 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11702 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11703 | |
| 11704 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11705 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11706 | EXPECT_EQ("hello world", response_data); |
| 11707 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11708 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11709 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11710 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11712 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11713 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11714 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11715 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11716 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11717 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11718 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11719 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11720 | |
| 11721 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11722 | ASSERT_TRUE(response); |
| 11723 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11724 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11725 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11726 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11727 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11728 | EXPECT_EQ("hello!", response_data); |
| 11729 | |
| 11730 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11731 | ASSERT_TRUE(response); |
| 11732 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11733 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11734 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11735 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11736 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11737 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11738 | } |
| 11739 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11740 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11741 | HttpRequestInfo request; |
| 11742 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11743 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11744 | |
| 11745 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11746 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11747 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11748 | MockRead("\r\n"), |
| 11749 | MockRead("hello world"), |
| 11750 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11751 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11752 | }; |
| 11753 | |
| 11754 | StaticSocketDataProvider first_transaction( |
| 11755 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11756 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11757 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11758 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11759 | ssl.ssl_info.cert = |
| 11760 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11761 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11762 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11763 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11764 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11765 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11766 | NULL, 0, NULL, 0); |
| 11767 | hanging_alternate_protocol_socket.set_connect_data( |
| 11768 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11769 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11770 | &hanging_alternate_protocol_socket); |
| 11771 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11772 | // 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] | 11773 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11774 | NULL, 0); |
| 11775 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11778 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11779 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11781 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11782 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11783 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11784 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11785 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11786 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11787 | |
| 11788 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11789 | ASSERT_TRUE(response); |
| 11790 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11791 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11792 | |
| 11793 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11794 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11795 | EXPECT_EQ("hello world", response_data); |
| 11796 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11797 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11798 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11799 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11800 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11801 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11802 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11803 | |
| 11804 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11805 | ASSERT_TRUE(response); |
| 11806 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11807 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11808 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11809 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11810 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11811 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11812 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11813 | } |
| 11814 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11815 | class CapturingProxyResolver : public ProxyResolver { |
| 11816 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11817 | CapturingProxyResolver() = default; |
| 11818 | ~CapturingProxyResolver() override = default; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11819 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11820 | int GetProxyForURL(const GURL& url, |
| 11821 | ProxyInfo* results, |
| 11822 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11823 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11824 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11825 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11826 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11827 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11828 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11829 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11830 | } |
| 11831 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11832 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11833 | |
| 11834 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11835 | std::vector<GURL> resolved_; |
| 11836 | |
| 11837 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11838 | }; |
| 11839 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11840 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11841 | public: |
| 11842 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11843 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11844 | |
| 11845 | int CreateProxyResolver( |
| 11846 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11847 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11848 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11849 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11850 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11851 | return OK; |
| 11852 | } |
| 11853 | |
| 11854 | private: |
| 11855 | ProxyResolver* resolver_; |
| 11856 | }; |
| 11857 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11858 | // Test that proxy is resolved using the origin url, |
| 11859 | // regardless of the alternative server. |
| 11860 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11861 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11862 | ProxyConfig proxy_config; |
| 11863 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11864 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11865 | auto proxy_config_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11866 | std::make_unique<ProxyConfigServiceFixed>(proxy_config); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11867 | |
| 11868 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11869 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11870 | &capturing_proxy_resolver); |
| 11871 | |
| 11872 | TestNetLog net_log; |
| 11873 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11874 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11875 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11876 | &net_log); |
| 11877 | |
| 11878 | session_deps_.net_log = &net_log; |
| 11879 | |
| 11880 | // Configure alternative service with a hostname that is not bypassed by the |
| 11881 | // proxy. |
| 11882 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11883 | HttpServerProperties* http_server_properties = |
| 11884 | session->http_server_properties(); |
| 11885 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11886 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11887 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11888 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11889 | http_server_properties->SetHttp2AlternativeService( |
| 11890 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11891 | |
| 11892 | // Non-alternative job should hang. |
| 11893 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11894 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11895 | nullptr, 0); |
| 11896 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11897 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11898 | &hanging_alternate_protocol_socket); |
| 11899 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11900 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11901 | |
| 11902 | HttpRequestInfo request; |
| 11903 | request.method = "GET"; |
| 11904 | request.url = GURL("https://www.example.org/"); |
| 11905 | request.load_flags = 0; |
| 11906 | |
| 11907 | SpdySerializedFrame req( |
| 11908 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11909 | |
| 11910 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11911 | |
| 11912 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11913 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11914 | MockRead spdy_reads[] = { |
| 11915 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11916 | }; |
| 11917 | |
| 11918 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11919 | arraysize(spdy_writes)); |
| 11920 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11921 | |
| 11922 | TestCompletionCallback callback; |
| 11923 | |
| 11924 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11925 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11926 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11927 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11928 | |
| 11929 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11930 | ASSERT_TRUE(response); |
| 11931 | ASSERT_TRUE(response->headers); |
| 11932 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11933 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11934 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11935 | |
| 11936 | std::string response_data; |
| 11937 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11938 | EXPECT_EQ("hello!", response_data); |
| 11939 | |
| 11940 | // Origin host bypasses proxy, no resolution should have happened. |
| 11941 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11942 | } |
| 11943 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11944 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11945 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11946 | proxy_config.set_auto_detect(true); |
| 11947 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11948 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11949 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11950 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 11951 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
| 11952 | std::make_unique<CapturingProxyResolverFactory>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11953 | &capturing_proxy_resolver), |
| 11954 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11955 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11956 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11957 | |
| 11958 | HttpRequestInfo request; |
| 11959 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11960 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11961 | |
| 11962 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11963 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11964 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11965 | MockRead("\r\n"), |
| 11966 | MockRead("hello world"), |
| 11967 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11968 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11969 | }; |
| 11970 | |
| 11971 | StaticSocketDataProvider first_transaction( |
| 11972 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11973 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11974 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11975 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11976 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11977 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11978 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11979 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11980 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11981 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11982 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11983 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11984 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11985 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11986 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11987 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11988 | }; |
| 11989 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11990 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11991 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11992 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11993 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11994 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11995 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11996 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11997 | }; |
| 11998 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11999 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12000 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12001 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12002 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12003 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12004 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 12005 | NULL, 0, NULL, 0); |
| 12006 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12007 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12008 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12009 | &hanging_non_alternate_protocol_socket); |
| 12010 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12011 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12012 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12013 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12014 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12015 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12016 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12017 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12018 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12019 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12020 | |
| 12021 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12022 | ASSERT_TRUE(response); |
| 12023 | ASSERT_TRUE(response->headers); |
| 12024 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 12025 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12026 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12027 | |
| 12028 | std::string response_data; |
| 12029 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 12030 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12031 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12032 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12033 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12034 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12035 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12036 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12037 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12038 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12039 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12040 | ASSERT_TRUE(response); |
| 12041 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12042 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12043 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12044 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12045 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12046 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12047 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12048 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 12049 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12050 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12051 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12052 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12053 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12054 | LoadTimingInfo load_timing_info; |
| 12055 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12056 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12057 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12058 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12059 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12060 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12061 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12062 | HttpRequestInfo request; |
| 12063 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12064 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12065 | |
| 12066 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12067 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12068 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12069 | MockRead("\r\n"), |
| 12070 | MockRead("hello world"), |
| 12071 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12072 | }; |
| 12073 | |
| 12074 | StaticSocketDataProvider first_transaction( |
| 12075 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12076 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12077 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12078 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12079 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12080 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12081 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12082 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12083 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12084 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12085 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12086 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12087 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12088 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12089 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12090 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12091 | }; |
| 12092 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12093 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12094 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12095 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12096 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 12097 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12098 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12099 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12100 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12101 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12102 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12103 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12104 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12105 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12106 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12107 | |
| 12108 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12109 | ASSERT_TRUE(response); |
| 12110 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12111 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12112 | |
| 12113 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12114 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12115 | EXPECT_EQ("hello world", response_data); |
| 12116 | |
| 12117 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12118 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12119 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 12120 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12121 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 12122 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 12123 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12124 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12125 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12126 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12127 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12128 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12129 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12130 | |
| 12131 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12132 | ASSERT_TRUE(response); |
| 12133 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12134 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12135 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12136 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12137 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12138 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12139 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12140 | } |
| 12141 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12142 | // GenerateAuthToken is a mighty big test. |
| 12143 | // It tests all permutation of GenerateAuthToken behavior: |
| 12144 | // - Synchronous and Asynchronous completion. |
| 12145 | // - OK or error on completion. |
| 12146 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 12147 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 12148 | // - Non-authenticating and authenticating backend. |
| 12149 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12150 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12151 | // problems generating an auth token for an authenticating proxy, we don't |
| 12152 | // need to test all permutations of the backend server). |
| 12153 | // |
| 12154 | // The test proceeds by going over each of the configuration cases, and |
| 12155 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 12156 | // specifies both the configuration for the test as well as the expectations |
| 12157 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12158 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12159 | static const char kServer[] = "http://www.example.com"; |
| 12160 | static const char kSecureServer[] = "https://www.example.com"; |
| 12161 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12162 | |
| 12163 | enum AuthTiming { |
| 12164 | AUTH_NONE, |
| 12165 | AUTH_SYNC, |
| 12166 | AUTH_ASYNC, |
| 12167 | }; |
| 12168 | |
| 12169 | const MockWrite kGet( |
| 12170 | "GET / HTTP/1.1\r\n" |
| 12171 | "Host: www.example.com\r\n" |
| 12172 | "Connection: keep-alive\r\n\r\n"); |
| 12173 | const MockWrite kGetProxy( |
| 12174 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12175 | "Host: www.example.com\r\n" |
| 12176 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12177 | const MockWrite kGetAuth( |
| 12178 | "GET / HTTP/1.1\r\n" |
| 12179 | "Host: www.example.com\r\n" |
| 12180 | "Connection: keep-alive\r\n" |
| 12181 | "Authorization: auth_token\r\n\r\n"); |
| 12182 | const MockWrite kGetProxyAuth( |
| 12183 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12184 | "Host: www.example.com\r\n" |
| 12185 | "Proxy-Connection: keep-alive\r\n" |
| 12186 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12187 | const MockWrite kGetAuthThroughProxy( |
| 12188 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12189 | "Host: www.example.com\r\n" |
| 12190 | "Proxy-Connection: keep-alive\r\n" |
| 12191 | "Authorization: auth_token\r\n\r\n"); |
| 12192 | const MockWrite kGetAuthWithProxyAuth( |
| 12193 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12194 | "Host: www.example.com\r\n" |
| 12195 | "Proxy-Connection: keep-alive\r\n" |
| 12196 | "Proxy-Authorization: auth_token\r\n" |
| 12197 | "Authorization: auth_token\r\n\r\n"); |
| 12198 | const MockWrite kConnect( |
| 12199 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12200 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12201 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12202 | const MockWrite kConnectProxyAuth( |
| 12203 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12204 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12205 | "Proxy-Connection: keep-alive\r\n" |
| 12206 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12207 | |
| 12208 | const MockRead kSuccess( |
| 12209 | "HTTP/1.1 200 OK\r\n" |
| 12210 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12211 | "Content-Length: 3\r\n\r\n" |
| 12212 | "Yes"); |
| 12213 | const MockRead kFailure( |
| 12214 | "Should not be called."); |
| 12215 | const MockRead kServerChallenge( |
| 12216 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12217 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12218 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12219 | "Content-Length: 14\r\n\r\n" |
| 12220 | "Unauthorized\r\n"); |
| 12221 | const MockRead kProxyChallenge( |
| 12222 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12223 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 12224 | "Proxy-Connection: close\r\n" |
| 12225 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12226 | "Content-Length: 14\r\n\r\n" |
| 12227 | "Unauthorized\r\n"); |
| 12228 | const MockRead kProxyConnected( |
| 12229 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 12230 | |
| 12231 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 12232 | // no constructors, but the C++ compiler on Windows warns about |
| 12233 | // unspecified data in compound literals. So, moved to using constructors, |
| 12234 | // and TestRound's created with the default constructor should not be used. |
| 12235 | struct TestRound { |
| 12236 | TestRound() |
| 12237 | : expected_rv(ERR_UNEXPECTED), |
| 12238 | extra_write(NULL), |
| 12239 | extra_read(NULL) { |
| 12240 | } |
| 12241 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12242 | int expected_rv_arg) |
| 12243 | : write(write_arg), |
| 12244 | read(read_arg), |
| 12245 | expected_rv(expected_rv_arg), |
| 12246 | extra_write(NULL), |
| 12247 | extra_read(NULL) { |
| 12248 | } |
| 12249 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12250 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 12251 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12252 | : write(write_arg), |
| 12253 | read(read_arg), |
| 12254 | expected_rv(expected_rv_arg), |
| 12255 | extra_write(extra_write_arg), |
| 12256 | extra_read(extra_read_arg) { |
| 12257 | } |
| 12258 | MockWrite write; |
| 12259 | MockRead read; |
| 12260 | int expected_rv; |
| 12261 | const MockWrite* extra_write; |
| 12262 | const MockRead* extra_read; |
| 12263 | }; |
| 12264 | |
| 12265 | static const int kNoSSL = 500; |
| 12266 | |
| 12267 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12268 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12269 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12270 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12271 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12272 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12273 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12274 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12275 | int num_auth_rounds; |
| 12276 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12277 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12278 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12279 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12280 | {__LINE__, |
| 12281 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12282 | AUTH_NONE, |
| 12283 | OK, |
| 12284 | kServer, |
| 12285 | AUTH_NONE, |
| 12286 | OK, |
| 12287 | 1, |
| 12288 | kNoSSL, |
| 12289 | {TestRound(kGet, kSuccess, OK)}}, |
| 12290 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12291 | {__LINE__, |
| 12292 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12293 | AUTH_NONE, |
| 12294 | OK, |
| 12295 | kServer, |
| 12296 | AUTH_SYNC, |
| 12297 | OK, |
| 12298 | 2, |
| 12299 | kNoSSL, |
| 12300 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12301 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12302 | {__LINE__, |
| 12303 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12304 | AUTH_NONE, |
| 12305 | OK, |
| 12306 | kServer, |
| 12307 | AUTH_SYNC, |
| 12308 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12309 | 3, |
| 12310 | kNoSSL, |
| 12311 | {TestRound(kGet, kServerChallenge, OK), |
| 12312 | TestRound(kGet, kServerChallenge, OK), |
| 12313 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12314 | {__LINE__, |
| 12315 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12316 | AUTH_NONE, |
| 12317 | OK, |
| 12318 | kServer, |
| 12319 | AUTH_SYNC, |
| 12320 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12321 | 2, |
| 12322 | kNoSSL, |
| 12323 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12324 | {__LINE__, |
| 12325 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12326 | AUTH_NONE, |
| 12327 | OK, |
| 12328 | kServer, |
| 12329 | AUTH_SYNC, |
| 12330 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 12331 | 2, |
| 12332 | kNoSSL, |
| 12333 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12334 | {__LINE__, |
| 12335 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12336 | AUTH_SYNC, |
| 12337 | ERR_FAILED, |
| 12338 | kServer, |
| 12339 | AUTH_NONE, |
| 12340 | OK, |
| 12341 | 2, |
| 12342 | kNoSSL, |
| 12343 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12344 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12345 | {__LINE__, |
| 12346 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12347 | AUTH_ASYNC, |
| 12348 | ERR_FAILED, |
| 12349 | kServer, |
| 12350 | AUTH_NONE, |
| 12351 | OK, |
| 12352 | 2, |
| 12353 | kNoSSL, |
| 12354 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12355 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12356 | {__LINE__, |
| 12357 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12358 | AUTH_NONE, |
| 12359 | OK, |
| 12360 | kServer, |
| 12361 | AUTH_SYNC, |
| 12362 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12363 | 2, |
| 12364 | kNoSSL, |
| 12365 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12366 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12367 | {__LINE__, |
| 12368 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12369 | AUTH_NONE, |
| 12370 | OK, |
| 12371 | kServer, |
| 12372 | AUTH_ASYNC, |
| 12373 | ERR_FAILED, |
| 12374 | 2, |
| 12375 | kNoSSL, |
| 12376 | {TestRound(kGet, kServerChallenge, OK), |
| 12377 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12378 | {__LINE__, |
| 12379 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12380 | AUTH_NONE, |
| 12381 | OK, |
| 12382 | kServer, |
| 12383 | AUTH_ASYNC, |
| 12384 | OK, |
| 12385 | 2, |
| 12386 | kNoSSL, |
| 12387 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12388 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12389 | {__LINE__, |
| 12390 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12391 | AUTH_NONE, |
| 12392 | OK, |
| 12393 | kServer, |
| 12394 | AUTH_ASYNC, |
| 12395 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12396 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12397 | kNoSSL, |
| 12398 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12399 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12400 | TestRound(kGet, kServerChallenge, OK), |
| 12401 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12402 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12403 | {__LINE__, |
| 12404 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12405 | AUTH_NONE, |
| 12406 | OK, |
| 12407 | kServer, |
| 12408 | AUTH_NONE, |
| 12409 | OK, |
| 12410 | 1, |
| 12411 | kNoSSL, |
| 12412 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12413 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12414 | {__LINE__, |
| 12415 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12416 | AUTH_NONE, |
| 12417 | OK, |
| 12418 | kServer, |
| 12419 | AUTH_SYNC, |
| 12420 | OK, |
| 12421 | 2, |
| 12422 | kNoSSL, |
| 12423 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12424 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12425 | {__LINE__, |
| 12426 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12427 | AUTH_NONE, |
| 12428 | OK, |
| 12429 | kServer, |
| 12430 | AUTH_SYNC, |
| 12431 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12432 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12433 | kNoSSL, |
| 12434 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12435 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12436 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12437 | {__LINE__, |
| 12438 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12439 | AUTH_NONE, |
| 12440 | OK, |
| 12441 | kServer, |
| 12442 | AUTH_ASYNC, |
| 12443 | OK, |
| 12444 | 2, |
| 12445 | kNoSSL, |
| 12446 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12447 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12448 | {__LINE__, |
| 12449 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12450 | AUTH_NONE, |
| 12451 | OK, |
| 12452 | kServer, |
| 12453 | AUTH_ASYNC, |
| 12454 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12455 | 2, |
| 12456 | kNoSSL, |
| 12457 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12458 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12459 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12460 | {__LINE__, |
| 12461 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12462 | AUTH_SYNC, |
| 12463 | OK, |
| 12464 | kServer, |
| 12465 | AUTH_NONE, |
| 12466 | OK, |
| 12467 | 2, |
| 12468 | kNoSSL, |
| 12469 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12470 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12471 | {__LINE__, |
| 12472 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12473 | AUTH_SYNC, |
| 12474 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12475 | kServer, |
| 12476 | AUTH_NONE, |
| 12477 | OK, |
| 12478 | 2, |
| 12479 | kNoSSL, |
| 12480 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12481 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12482 | {__LINE__, |
| 12483 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12484 | AUTH_ASYNC, |
| 12485 | OK, |
| 12486 | kServer, |
| 12487 | AUTH_NONE, |
| 12488 | OK, |
| 12489 | 2, |
| 12490 | kNoSSL, |
| 12491 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12492 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12493 | {__LINE__, |
| 12494 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12495 | AUTH_ASYNC, |
| 12496 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12497 | kServer, |
| 12498 | AUTH_NONE, |
| 12499 | OK, |
| 12500 | 2, |
| 12501 | kNoSSL, |
| 12502 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12503 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12504 | {__LINE__, |
| 12505 | kProxy, |
| 12506 | AUTH_ASYNC, |
| 12507 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12508 | kServer, |
| 12509 | AUTH_NONE, |
| 12510 | OK, |
| 12511 | 3, |
| 12512 | kNoSSL, |
| 12513 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12514 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12515 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12516 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12517 | {__LINE__, |
| 12518 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12519 | AUTH_SYNC, |
| 12520 | OK, |
| 12521 | kServer, |
| 12522 | AUTH_SYNC, |
| 12523 | OK, |
| 12524 | 3, |
| 12525 | kNoSSL, |
| 12526 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12527 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12528 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12529 | {__LINE__, |
| 12530 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12531 | AUTH_SYNC, |
| 12532 | OK, |
| 12533 | kServer, |
| 12534 | AUTH_SYNC, |
| 12535 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12536 | 3, |
| 12537 | kNoSSL, |
| 12538 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12539 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12540 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12541 | {__LINE__, |
| 12542 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12543 | AUTH_ASYNC, |
| 12544 | OK, |
| 12545 | kServer, |
| 12546 | AUTH_SYNC, |
| 12547 | OK, |
| 12548 | 3, |
| 12549 | kNoSSL, |
| 12550 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12551 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12552 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12553 | {__LINE__, |
| 12554 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12555 | AUTH_ASYNC, |
| 12556 | OK, |
| 12557 | kServer, |
| 12558 | AUTH_SYNC, |
| 12559 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12560 | 3, |
| 12561 | kNoSSL, |
| 12562 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12563 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12564 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12565 | {__LINE__, |
| 12566 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12567 | AUTH_SYNC, |
| 12568 | OK, |
| 12569 | kServer, |
| 12570 | AUTH_ASYNC, |
| 12571 | OK, |
| 12572 | 3, |
| 12573 | kNoSSL, |
| 12574 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12575 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12576 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12577 | {__LINE__, |
| 12578 | kProxy, |
| 12579 | AUTH_SYNC, |
| 12580 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12581 | kServer, |
| 12582 | AUTH_ASYNC, |
| 12583 | OK, |
| 12584 | 4, |
| 12585 | kNoSSL, |
| 12586 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12587 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12588 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12589 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12590 | {__LINE__, |
| 12591 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12592 | AUTH_SYNC, |
| 12593 | OK, |
| 12594 | kServer, |
| 12595 | AUTH_ASYNC, |
| 12596 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12597 | 3, |
| 12598 | kNoSSL, |
| 12599 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12600 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12601 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12602 | {__LINE__, |
| 12603 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12604 | AUTH_ASYNC, |
| 12605 | OK, |
| 12606 | kServer, |
| 12607 | AUTH_ASYNC, |
| 12608 | OK, |
| 12609 | 3, |
| 12610 | kNoSSL, |
| 12611 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12612 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12613 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12614 | {__LINE__, |
| 12615 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12616 | AUTH_ASYNC, |
| 12617 | OK, |
| 12618 | kServer, |
| 12619 | AUTH_ASYNC, |
| 12620 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12621 | 3, |
| 12622 | kNoSSL, |
| 12623 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12624 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12625 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12626 | {__LINE__, |
| 12627 | kProxy, |
| 12628 | AUTH_ASYNC, |
| 12629 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12630 | kServer, |
| 12631 | AUTH_ASYNC, |
| 12632 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12633 | 4, |
| 12634 | kNoSSL, |
| 12635 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12636 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12637 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12638 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12639 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12640 | {__LINE__, |
| 12641 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12642 | AUTH_NONE, |
| 12643 | OK, |
| 12644 | kSecureServer, |
| 12645 | AUTH_NONE, |
| 12646 | OK, |
| 12647 | 1, |
| 12648 | 0, |
| 12649 | {TestRound(kGet, kSuccess, OK)}}, |
| 12650 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12651 | {__LINE__, |
| 12652 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12653 | AUTH_NONE, |
| 12654 | OK, |
| 12655 | kSecureServer, |
| 12656 | AUTH_SYNC, |
| 12657 | OK, |
| 12658 | 2, |
| 12659 | 0, |
| 12660 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12661 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12662 | {__LINE__, |
| 12663 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12664 | AUTH_NONE, |
| 12665 | OK, |
| 12666 | kSecureServer, |
| 12667 | AUTH_SYNC, |
| 12668 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12669 | 2, |
| 12670 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12671 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12672 | {__LINE__, |
| 12673 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12674 | AUTH_NONE, |
| 12675 | OK, |
| 12676 | kSecureServer, |
| 12677 | AUTH_ASYNC, |
| 12678 | OK, |
| 12679 | 2, |
| 12680 | 0, |
| 12681 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12682 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12683 | {__LINE__, |
| 12684 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12685 | AUTH_NONE, |
| 12686 | OK, |
| 12687 | kSecureServer, |
| 12688 | AUTH_ASYNC, |
| 12689 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12690 | 2, |
| 12691 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12692 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12693 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12694 | {__LINE__, |
| 12695 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12696 | AUTH_NONE, |
| 12697 | OK, |
| 12698 | kSecureServer, |
| 12699 | AUTH_NONE, |
| 12700 | OK, |
| 12701 | 1, |
| 12702 | 0, |
| 12703 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 12704 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12705 | {__LINE__, |
| 12706 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12707 | AUTH_NONE, |
| 12708 | OK, |
| 12709 | kSecureServer, |
| 12710 | AUTH_SYNC, |
| 12711 | OK, |
| 12712 | 2, |
| 12713 | 0, |
| 12714 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12715 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12716 | {__LINE__, |
| 12717 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12718 | AUTH_NONE, |
| 12719 | OK, |
| 12720 | kSecureServer, |
| 12721 | AUTH_SYNC, |
| 12722 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12723 | 2, |
| 12724 | 0, |
| 12725 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12726 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12727 | {__LINE__, |
| 12728 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12729 | AUTH_NONE, |
| 12730 | OK, |
| 12731 | kSecureServer, |
| 12732 | AUTH_ASYNC, |
| 12733 | OK, |
| 12734 | 2, |
| 12735 | 0, |
| 12736 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12737 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12738 | {__LINE__, |
| 12739 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12740 | AUTH_NONE, |
| 12741 | OK, |
| 12742 | kSecureServer, |
| 12743 | AUTH_ASYNC, |
| 12744 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12745 | 2, |
| 12746 | 0, |
| 12747 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12748 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12749 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12750 | {__LINE__, |
| 12751 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12752 | AUTH_SYNC, |
| 12753 | OK, |
| 12754 | kSecureServer, |
| 12755 | AUTH_NONE, |
| 12756 | OK, |
| 12757 | 2, |
| 12758 | 1, |
| 12759 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12760 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12761 | {__LINE__, |
| 12762 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12763 | AUTH_SYNC, |
| 12764 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12765 | kSecureServer, |
| 12766 | AUTH_NONE, |
| 12767 | OK, |
| 12768 | 2, |
| 12769 | kNoSSL, |
| 12770 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12771 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12772 | {__LINE__, |
| 12773 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12774 | AUTH_SYNC, |
| 12775 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12776 | kSecureServer, |
| 12777 | AUTH_NONE, |
| 12778 | OK, |
| 12779 | 2, |
| 12780 | kNoSSL, |
| 12781 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12782 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12783 | {__LINE__, |
| 12784 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12785 | AUTH_SYNC, |
| 12786 | ERR_UNEXPECTED, |
| 12787 | kSecureServer, |
| 12788 | AUTH_NONE, |
| 12789 | OK, |
| 12790 | 2, |
| 12791 | kNoSSL, |
| 12792 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12793 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12794 | {__LINE__, |
| 12795 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12796 | AUTH_ASYNC, |
| 12797 | OK, |
| 12798 | kSecureServer, |
| 12799 | AUTH_NONE, |
| 12800 | OK, |
| 12801 | 2, |
| 12802 | 1, |
| 12803 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12804 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12805 | {__LINE__, |
| 12806 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12807 | AUTH_ASYNC, |
| 12808 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12809 | kSecureServer, |
| 12810 | AUTH_NONE, |
| 12811 | OK, |
| 12812 | 2, |
| 12813 | kNoSSL, |
| 12814 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12815 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12816 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12817 | {__LINE__, |
| 12818 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12819 | AUTH_SYNC, |
| 12820 | OK, |
| 12821 | kSecureServer, |
| 12822 | AUTH_SYNC, |
| 12823 | OK, |
| 12824 | 3, |
| 12825 | 1, |
| 12826 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12827 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12828 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12829 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12830 | {__LINE__, |
| 12831 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12832 | AUTH_SYNC, |
| 12833 | OK, |
| 12834 | kSecureServer, |
| 12835 | AUTH_SYNC, |
| 12836 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12837 | 3, |
| 12838 | 1, |
| 12839 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12840 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12841 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12842 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12843 | {__LINE__, |
| 12844 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12845 | AUTH_ASYNC, |
| 12846 | OK, |
| 12847 | kSecureServer, |
| 12848 | AUTH_SYNC, |
| 12849 | OK, |
| 12850 | 3, |
| 12851 | 1, |
| 12852 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12853 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12854 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12855 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12856 | {__LINE__, |
| 12857 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12858 | AUTH_ASYNC, |
| 12859 | OK, |
| 12860 | kSecureServer, |
| 12861 | AUTH_SYNC, |
| 12862 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12863 | 3, |
| 12864 | 1, |
| 12865 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12866 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12867 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12868 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12869 | {__LINE__, |
| 12870 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12871 | AUTH_SYNC, |
| 12872 | OK, |
| 12873 | kSecureServer, |
| 12874 | AUTH_ASYNC, |
| 12875 | OK, |
| 12876 | 3, |
| 12877 | 1, |
| 12878 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12879 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12880 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12881 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12882 | {__LINE__, |
| 12883 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12884 | AUTH_SYNC, |
| 12885 | OK, |
| 12886 | kSecureServer, |
| 12887 | AUTH_ASYNC, |
| 12888 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12889 | 3, |
| 12890 | 1, |
| 12891 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12892 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12893 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12894 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12895 | {__LINE__, |
| 12896 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12897 | AUTH_ASYNC, |
| 12898 | OK, |
| 12899 | kSecureServer, |
| 12900 | AUTH_ASYNC, |
| 12901 | OK, |
| 12902 | 3, |
| 12903 | 1, |
| 12904 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12905 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12906 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12907 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12908 | {__LINE__, |
| 12909 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12910 | AUTH_ASYNC, |
| 12911 | OK, |
| 12912 | kSecureServer, |
| 12913 | AUTH_ASYNC, |
| 12914 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12915 | 3, |
| 12916 | 1, |
| 12917 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12918 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12919 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12920 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12921 | {__LINE__, |
| 12922 | kProxy, |
| 12923 | AUTH_ASYNC, |
| 12924 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12925 | kSecureServer, |
| 12926 | AUTH_ASYNC, |
| 12927 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12928 | 4, |
| 12929 | 2, |
| 12930 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12931 | TestRound(kConnect, kProxyChallenge, OK), |
| 12932 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12933 | &kServerChallenge), |
| 12934 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12935 | }; |
| 12936 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12937 | for (const auto& test_config : test_configs) { |
| 12938 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12939 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12940 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12941 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12942 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12943 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12944 | |
| 12945 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12946 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12947 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12948 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12949 | std::string auth_challenge = "Mock realm=proxy"; |
| 12950 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12951 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12952 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12953 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12954 | empty_ssl_info, origin, |
| 12955 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12956 | auth_handler->SetGenerateExpectation( |
| 12957 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12958 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12959 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12960 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12961 | } |
| 12962 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12963 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12964 | std::string auth_challenge = "Mock realm=server"; |
| 12965 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12966 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12967 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12968 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12969 | empty_ssl_info, origin, |
| 12970 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12971 | auth_handler->SetGenerateExpectation( |
| 12972 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12973 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12974 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12975 | |
| 12976 | // The second handler always succeeds. It should only be used where there |
| 12977 | // are multiple auth sessions for server auth in the same network |
| 12978 | // transaction using the same auth scheme. |
| 12979 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12980 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12981 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12982 | empty_ssl_info, origin, |
| 12983 | NetLogWithSource()); |
| 12984 | second_handler->SetGenerateExpectation(true, OK); |
| 12985 | auth_factory->AddMockHandler(second_handler.release(), |
| 12986 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12987 | } |
| 12988 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12989 | session_deps_.proxy_service = |
| 12990 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12991 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12992 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12993 | } |
| 12994 | |
| 12995 | HttpRequestInfo request; |
| 12996 | request.method = "GET"; |
| 12997 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12998 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12999 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13000 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13001 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 13002 | |
| 13003 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 13004 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13005 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13006 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13007 | const TestRound& read_write_round = test_config.rounds[round]; |
| 13008 | |
| 13009 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13010 | mock_reads.back().push_back(read_write_round.read); |
| 13011 | mock_writes.back().push_back(read_write_round.write); |
| 13012 | |
| 13013 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 13014 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 13015 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13016 | mock_reads.push_back(std::vector<MockRead>()); |
| 13017 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13018 | } |
| 13019 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13020 | if (read_write_round.extra_read) { |
| 13021 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13022 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13023 | if (read_write_round.extra_write) { |
| 13024 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 13025 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13026 | |
| 13027 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13028 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13029 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13030 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13031 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13032 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13033 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13034 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13035 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13036 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13037 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13038 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 13039 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13040 | } |
| 13041 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13042 | // Transaction must be created after DataProviders, so it's destroyed before |
| 13043 | // they are as well. |
| 13044 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13045 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13046 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13047 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13048 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13049 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13050 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13051 | int rv; |
| 13052 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13053 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13054 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13055 | rv = trans.RestartWithAuth( |
| 13056 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13057 | } |
| 13058 | if (rv == ERR_IO_PENDING) |
| 13059 | rv = callback.WaitForResult(); |
| 13060 | |
| 13061 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13062 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13063 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 13064 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13065 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 13066 | continue; |
| 13067 | } |
| 13068 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13069 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13070 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13071 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13072 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13073 | } |
| 13074 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 13075 | } |
| 13076 | } |
| 13077 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13078 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13079 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13080 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13081 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13082 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13083 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13084 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 13085 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13086 | |
| 13087 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13088 | auth_handler->set_connection_based(true); |
| 13089 | std::string auth_challenge = "Mock realm=server"; |
| 13090 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13091 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13092 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13093 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13094 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13095 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13096 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13097 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13098 | int rv = OK; |
| 13099 | const HttpResponseInfo* response = NULL; |
| 13100 | HttpRequestInfo request; |
| 13101 | request.method = "GET"; |
| 13102 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13103 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13104 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13105 | |
| 13106 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 13107 | // to validate that the TCP socket is not released to the pool between |
| 13108 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13109 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13110 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13111 | 50, // Max sockets for pool |
| 13112 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 13113 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 13114 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13115 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 13116 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 13117 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13118 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13119 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13120 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13121 | |
| 13122 | const MockWrite kGet( |
| 13123 | "GET / HTTP/1.1\r\n" |
| 13124 | "Host: www.example.com\r\n" |
| 13125 | "Connection: keep-alive\r\n\r\n"); |
| 13126 | const MockWrite kGetAuth( |
| 13127 | "GET / HTTP/1.1\r\n" |
| 13128 | "Host: www.example.com\r\n" |
| 13129 | "Connection: keep-alive\r\n" |
| 13130 | "Authorization: auth_token\r\n\r\n"); |
| 13131 | |
| 13132 | const MockRead kServerChallenge( |
| 13133 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13134 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13135 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13136 | "Content-Length: 14\r\n\r\n" |
| 13137 | "Unauthorized\r\n"); |
| 13138 | const MockRead kSuccess( |
| 13139 | "HTTP/1.1 200 OK\r\n" |
| 13140 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13141 | "Content-Length: 3\r\n\r\n" |
| 13142 | "Yes"); |
| 13143 | |
| 13144 | MockWrite writes[] = { |
| 13145 | // First round |
| 13146 | kGet, |
| 13147 | // Second round |
| 13148 | kGetAuth, |
| 13149 | // Third round |
| 13150 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13151 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13152 | kGetAuth, |
| 13153 | // Competing request |
| 13154 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13155 | }; |
| 13156 | MockRead reads[] = { |
| 13157 | // First round |
| 13158 | kServerChallenge, |
| 13159 | // Second round |
| 13160 | kServerChallenge, |
| 13161 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13162 | kServerChallenge, |
| 13163 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13164 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13165 | // Competing response |
| 13166 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13167 | }; |
| 13168 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 13169 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13170 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13171 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13172 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13173 | |
| 13174 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13175 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13176 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13177 | if (rv == ERR_IO_PENDING) |
| 13178 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13179 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13180 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13181 | ASSERT_TRUE(response); |
| 13182 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13183 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13184 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13185 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13186 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13187 | // In between rounds, another request comes in for the same domain. |
| 13188 | // It should not be able to grab the TCP socket that trans has already |
| 13189 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13190 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13191 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13192 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 13193 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13194 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13195 | // callback_compete.WaitForResult at this point would stall forever, |
| 13196 | // since the HttpNetworkTransaction does not release the request back to |
| 13197 | // the pool until after authentication completes. |
| 13198 | |
| 13199 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13200 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13201 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13202 | if (rv == ERR_IO_PENDING) |
| 13203 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13204 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13205 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13206 | ASSERT_TRUE(response); |
| 13207 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13208 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13209 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13210 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13211 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13212 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13213 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13214 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13215 | if (rv == ERR_IO_PENDING) |
| 13216 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13217 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13218 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13219 | ASSERT_TRUE(response); |
| 13220 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13221 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13222 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13223 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13224 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13225 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13226 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13227 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13228 | if (rv == ERR_IO_PENDING) |
| 13229 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13230 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13231 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13232 | ASSERT_TRUE(response); |
| 13233 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13234 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13235 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13236 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 13237 | // auth handler should transition to a DONE state in concert with the remote |
| 13238 | // server. But that's not something we can test here with a mock handler. |
| 13239 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 13240 | auth_handler->state()); |
| 13241 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13242 | // Read the body since the fourth round was successful. This will also |
| 13243 | // release the socket back to the pool. |
| 13244 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13245 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13246 | if (rv == ERR_IO_PENDING) |
| 13247 | rv = callback.WaitForResult(); |
| 13248 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13249 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13250 | EXPECT_EQ(0, rv); |
| 13251 | // There are still 0 idle sockets, since the trans_compete transaction |
| 13252 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13253 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13254 | |
| 13255 | // The competing request can now finish. Wait for the headers and then |
| 13256 | // read the body. |
| 13257 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13258 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13259 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13260 | if (rv == ERR_IO_PENDING) |
| 13261 | rv = callback.WaitForResult(); |
| 13262 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13263 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13264 | EXPECT_EQ(0, rv); |
| 13265 | |
| 13266 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13267 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13268 | } |
| 13269 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13270 | // This tests the case that a request is issued via http instead of spdy after |
| 13271 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13272 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13273 | HttpRequestInfo request; |
| 13274 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13275 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13276 | |
| 13277 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13278 | MockWrite( |
| 13279 | "GET / HTTP/1.1\r\n" |
| 13280 | "Host: www.example.org\r\n" |
| 13281 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13282 | }; |
| 13283 | |
| 13284 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13285 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13286 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13287 | MockRead("\r\n"), |
| 13288 | MockRead("hello world"), |
| 13289 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13290 | }; |
| 13291 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13292 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13293 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13294 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13295 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13296 | |
| 13297 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13298 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13299 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13300 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13301 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13302 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13303 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13304 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13305 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13306 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13307 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13308 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13309 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13310 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13311 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13312 | ASSERT_TRUE(response); |
| 13313 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13314 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13315 | |
| 13316 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13317 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13318 | EXPECT_EQ("hello world", response_data); |
| 13319 | |
| 13320 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13321 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13322 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13323 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13324 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 13325 | // immediate server closing of the socket. |
| 13326 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13327 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13328 | HttpRequestInfo request; |
| 13329 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13330 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13331 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13332 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13333 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13334 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13335 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13336 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13337 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13338 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13339 | |
| 13340 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13341 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13342 | }; |
| 13343 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13344 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13345 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13346 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13347 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13348 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13349 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13350 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13351 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13352 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13353 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13354 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13355 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13356 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13357 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13358 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 13359 | // it gets it. This is needed since the auth handler may get destroyed |
| 13360 | // before we get a chance to query it. |
| 13361 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 13362 | public: |
| 13363 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 13364 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 13365 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13366 | |
| 13367 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13368 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 13369 | const HttpRequestInfo* request, |
| 13370 | const CompletionCallback& callback, |
| 13371 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13372 | *url_ = request->url; |
| 13373 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 13374 | credentials, request, callback, auth_token); |
| 13375 | } |
| 13376 | |
| 13377 | private: |
| 13378 | GURL* url_; |
| 13379 | }; |
| 13380 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13381 | // Test that if we cancel the transaction as the connection is completing, that |
| 13382 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13383 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13384 | // Setup everything about the connection to complete synchronously, so that |
| 13385 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13386 | // for is the callback from the HttpStreamRequest. |
| 13387 | // Then cancel the transaction. |
| 13388 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13389 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13390 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13391 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13392 | MockRead(SYNCHRONOUS, "hello world"), |
| 13393 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13394 | }; |
| 13395 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13396 | HttpRequestInfo request; |
| 13397 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13398 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13399 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13400 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13401 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13402 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13403 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13404 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13405 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13406 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13407 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13408 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13409 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13410 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13411 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13412 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13413 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13414 | trans.reset(); // Cancel the transaction here. |
| 13415 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13416 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13417 | } |
| 13418 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13419 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13420 | // stream is drained properly and added back to the socket pool. The main |
| 13421 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13422 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13423 | // deleted. |
| 13424 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13425 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13426 | MockRead data_reads[] = { |
| 13427 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13428 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13429 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13430 | MockRead(ASYNC, "1"), |
| 13431 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13432 | // HttpNetworkTransaction has been deleted. |
| 13433 | MockRead(ASYNC, "2"), |
| 13434 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13435 | }; |
| 13436 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13437 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13438 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13439 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13440 | |
| 13441 | { |
| 13442 | HttpRequestInfo request; |
| 13443 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13444 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13445 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13446 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13447 | TestCompletionCallback callback; |
| 13448 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13449 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13450 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13451 | callback.WaitForResult(); |
| 13452 | |
| 13453 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13454 | ASSERT_TRUE(response); |
| 13455 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13456 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13457 | |
| 13458 | // The transaction and HttpRequestInfo are deleted. |
| 13459 | } |
| 13460 | |
| 13461 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13462 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13463 | |
| 13464 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13465 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13466 | } |
| 13467 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13468 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13469 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13470 | session_deps_.proxy_service = |
| 13471 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13472 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13473 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13474 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13475 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13476 | HttpRequestInfo request; |
| 13477 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13478 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13479 | |
| 13480 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13481 | MockWrite( |
| 13482 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13483 | "Host: www.example.org\r\n" |
| 13484 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13485 | }; |
| 13486 | |
| 13487 | MockRead data_reads1[] = { |
| 13488 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13489 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13490 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13491 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13492 | }; |
| 13493 | |
| 13494 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13495 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13496 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13497 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13498 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13499 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13500 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13501 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13502 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13503 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13504 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13505 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13506 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13507 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13508 | |
| 13509 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13510 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13511 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13512 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13513 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13514 | |
| 13515 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13516 | EXPECT_EQ(200, response->headers->response_code()); |
| 13517 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13518 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13519 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13520 | HostPortPair::FromString("myproxy:70")), |
| 13521 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13522 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13523 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13524 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13525 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13526 | |
| 13527 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13528 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13529 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13530 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13531 | } |
| 13532 | |
| 13533 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13534 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13535 | session_deps_.proxy_service = |
| 13536 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13537 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13538 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13539 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13540 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13541 | HttpRequestInfo request; |
| 13542 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13543 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13544 | |
| 13545 | // Since we have proxy, should try to establish tunnel. |
| 13546 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13547 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13548 | "Host: www.example.org:443\r\n" |
| 13549 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13550 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13551 | MockWrite("GET / HTTP/1.1\r\n" |
| 13552 | "Host: www.example.org\r\n" |
| 13553 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13554 | }; |
| 13555 | |
| 13556 | MockRead data_reads1[] = { |
| 13557 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13558 | |
| 13559 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13560 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13561 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13562 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13563 | }; |
| 13564 | |
| 13565 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13566 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13567 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13568 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13570 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13571 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13572 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13573 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13574 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13575 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13576 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13577 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13578 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13579 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13580 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13581 | |
| 13582 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13583 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13584 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13585 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13586 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13587 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13588 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13589 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13590 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13591 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13592 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13593 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13594 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13595 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13596 | |
| 13597 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13598 | EXPECT_EQ(200, response->headers->response_code()); |
| 13599 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13600 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13601 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13602 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13603 | HostPortPair::FromString("myproxy:70")), |
| 13604 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13605 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13606 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13607 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13608 | |
| 13609 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13610 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13611 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13612 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13613 | } |
| 13614 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13615 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13616 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13617 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13618 | session_deps_.proxy_service = |
| 13619 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 13620 | BoundTestNetLog log; |
| 13621 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13622 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13623 | |
| 13624 | HttpRequestInfo request; |
| 13625 | request.method = "GET"; |
| 13626 | request.url = GURL("https://[::1]:443/"); |
| 13627 | |
| 13628 | // Since we have proxy, should try to establish tunnel. |
| 13629 | MockWrite data_writes1[] = { |
| 13630 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13631 | "Host: [::1]:443\r\n" |
| 13632 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13633 | |
| 13634 | MockWrite("GET / HTTP/1.1\r\n" |
| 13635 | "Host: [::1]\r\n" |
| 13636 | "Connection: keep-alive\r\n\r\n"), |
| 13637 | }; |
| 13638 | |
| 13639 | MockRead data_reads1[] = { |
| 13640 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13641 | |
| 13642 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13643 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13644 | MockRead("Content-Length: 100\r\n\r\n"), |
| 13645 | MockRead(SYNCHRONOUS, OK), |
| 13646 | }; |
| 13647 | |
| 13648 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13649 | data_writes1, arraysize(data_writes1)); |
| 13650 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13651 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13652 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13653 | |
| 13654 | TestCompletionCallback callback1; |
| 13655 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13656 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13657 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13658 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13659 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13660 | |
| 13661 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13662 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13663 | TestNetLogEntry::List entries; |
| 13664 | log.GetEntries(&entries); |
| 13665 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13666 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13667 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13668 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13669 | entries, pos, |
| 13670 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13671 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13672 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13673 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13674 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13675 | |
| 13676 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13677 | EXPECT_EQ(200, response->headers->response_code()); |
| 13678 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13679 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13680 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13681 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13682 | HostPortPair::FromString("myproxy:70")), |
| 13683 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13684 | |
| 13685 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13686 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13687 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13688 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13689 | } |
| 13690 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13691 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 13692 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13693 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13694 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13695 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13696 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13697 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13698 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13699 | HttpRequestInfo request; |
| 13700 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13701 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13702 | |
| 13703 | // Since we have proxy, should try to establish tunnel. |
| 13704 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13705 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13706 | "Host: www.example.org:443\r\n" |
| 13707 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13708 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13709 | MockWrite("GET / HTTP/1.1\r\n" |
| 13710 | "Host: www.example.org\r\n" |
| 13711 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13712 | }; |
| 13713 | |
| 13714 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13715 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13716 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13717 | }; |
| 13718 | |
| 13719 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13720 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13721 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13722 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13725 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13726 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13727 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13729 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13730 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13731 | |
| 13732 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13733 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13734 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13735 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13736 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13737 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13738 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13739 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13740 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13741 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13742 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13743 | } |
| 13744 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13745 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13746 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13747 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13748 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13749 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13750 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13751 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13752 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13753 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13754 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13755 | }; |
| 13756 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13757 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13758 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13759 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13760 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13761 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13762 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13763 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13764 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13765 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13766 | |
| 13767 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13768 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13769 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 13770 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13771 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13772 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13773 | |
| 13774 | HttpRequestInfo request; |
| 13775 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13776 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13777 | |
| 13778 | // This is the important line that marks this as a preconnect. |
| 13779 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13780 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13781 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13782 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13783 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13784 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13785 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13786 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13787 | } |
| 13788 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13789 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13790 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13791 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13792 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13793 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13794 | request_info.url = GURL("https://www.example.com/"); |
| 13795 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13796 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13797 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13798 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13799 | MockWrite data_writes[] = { |
| 13800 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13801 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13802 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13803 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13804 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13805 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13806 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13807 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13808 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13809 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13810 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13811 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13812 | rv = callback.WaitForResult(); |
| 13813 | ASSERT_EQ(error, rv); |
| 13814 | } |
| 13815 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13816 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13817 | // Just check a grab bag of cert errors. |
| 13818 | static const int kErrors[] = { |
| 13819 | ERR_CERT_COMMON_NAME_INVALID, |
| 13820 | ERR_CERT_AUTHORITY_INVALID, |
| 13821 | ERR_CERT_DATE_INVALID, |
| 13822 | }; |
| 13823 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13824 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13825 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13826 | } |
| 13827 | } |
| 13828 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13829 | // Ensure that a client certificate is removed from the SSL client auth |
| 13830 | // cache when: |
| 13831 | // 1) No proxy is involved. |
| 13832 | // 2) TLS False Start is disabled. |
| 13833 | // 3) The initial TLS handshake requests a client certificate. |
| 13834 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13835 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13836 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13837 | request_info.url = GURL("https://www.example.com/"); |
| 13838 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13839 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13840 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13841 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13842 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13843 | |
| 13844 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13845 | // CertificateRequest is received for the first time, the handshake will |
| 13846 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13847 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13848 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13849 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13850 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13851 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13852 | |
| 13853 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13854 | // False Start is not being used, the result of the SSL handshake will be |
| 13855 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13856 | // matches the result of a server sending a handshake_failure alert, |
| 13857 | // rather than a Finished message, because it requires a client |
| 13858 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13859 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13860 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13861 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13862 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13863 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13864 | |
| 13865 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13866 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13867 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13868 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13869 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13870 | // requiring a client certificate, this fallback handshake should also |
| 13871 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13872 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13873 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13874 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13875 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13876 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13877 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13878 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13879 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13880 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13881 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13882 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13883 | // requiring a client certificate, this fallback handshake should also |
| 13884 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13885 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13886 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13887 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13888 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13889 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13890 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13891 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13892 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13893 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13894 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13895 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13896 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13897 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13898 | |
| 13899 | // Complete the SSL handshake, which should abort due to requiring a |
| 13900 | // client certificate. |
| 13901 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13902 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13903 | |
| 13904 | // Indicate that no certificate should be supplied. From the perspective |
| 13905 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13906 | // certificate, so this is the same as supply a |
| 13907 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13908 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13909 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13910 | |
| 13911 | // Ensure the certificate was added to the client auth cache before |
| 13912 | // allowing the connection to continue restarting. |
| 13913 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13914 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13915 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13916 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13917 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13918 | |
| 13919 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13920 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13921 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13922 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13923 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13924 | |
| 13925 | // Ensure that the client certificate is removed from the cache on a |
| 13926 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13927 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13928 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13929 | } |
| 13930 | |
| 13931 | // Ensure that a client certificate is removed from the SSL client auth |
| 13932 | // cache when: |
| 13933 | // 1) No proxy is involved. |
| 13934 | // 2) TLS False Start is enabled. |
| 13935 | // 3) The initial TLS handshake requests a client certificate. |
| 13936 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13937 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13938 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13939 | request_info.url = GURL("https://www.example.com/"); |
| 13940 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13941 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13942 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13943 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13944 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13945 | |
| 13946 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13947 | // return successfully after reading up to the peer's Certificate message. |
| 13948 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13949 | // enqueue application data to be sent in the same packet as the |
| 13950 | // ChangeCipherSpec and Finished messages. |
| 13951 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13952 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13953 | // Finished messages. If there was an error negotiating with the peer, |
| 13954 | // such as due to the peer requiring a client certificate when none was |
| 13955 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13956 | // called. |
| 13957 | |
| 13958 | // Like the non-False Start case, when a client certificate is requested by |
| 13959 | // the peer, the handshake is aborted during the Connect() call. |
| 13960 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13961 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13962 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13963 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13964 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13965 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13966 | |
| 13967 | // When a client certificate is supplied, Connect() will not be aborted |
| 13968 | // when the peer requests the certificate. Instead, the handshake will |
| 13969 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13970 | // the socket. The handshake messages are not processed until Read() is |
| 13971 | // called, which then detects that the handshake was aborted, due to the |
| 13972 | // peer sending a handshake_failure because it requires a client |
| 13973 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13974 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13975 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13976 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13977 | MockRead data2_reads[] = { |
| 13978 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13979 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13980 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13981 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13982 | |
| 13983 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13984 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13985 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13986 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13987 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13988 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13989 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13990 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13991 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13992 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13993 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13994 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13995 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13996 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13997 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13998 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13999 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14000 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14001 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14002 | ssl_data5.cert_request_info = cert_request.get(); |
| 14003 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14004 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14005 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 14006 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14007 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14008 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14009 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14010 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14011 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14012 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14013 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14014 | |
| 14015 | // Complete the SSL handshake, which should abort due to requiring a |
| 14016 | // client certificate. |
| 14017 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14018 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14019 | |
| 14020 | // Indicate that no certificate should be supplied. From the perspective |
| 14021 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14022 | // certificate, so this is the same as supply a |
| 14023 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14024 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14025 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14026 | |
| 14027 | // Ensure the certificate was added to the client auth cache before |
| 14028 | // allowing the connection to continue restarting. |
| 14029 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14030 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14031 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14032 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14033 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14034 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14035 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14036 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14037 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14038 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14039 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14040 | |
| 14041 | // Ensure that the client certificate is removed from the cache on a |
| 14042 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14043 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14044 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14045 | } |
| 14046 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14047 | // Ensure that a client certificate is removed from the SSL client auth |
| 14048 | // cache when: |
| 14049 | // 1) An HTTPS proxy is involved. |
| 14050 | // 3) The HTTPS proxy requests a client certificate. |
| 14051 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 14052 | // proxy. |
| 14053 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 14054 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14055 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14056 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14057 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14058 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14059 | |
| 14060 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14061 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14062 | |
| 14063 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 14064 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 14065 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 14066 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14067 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14068 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14069 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14070 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14071 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14072 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14073 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14074 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14075 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14076 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14077 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14078 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14079 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 14080 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14081 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14082 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14083 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14084 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14085 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14086 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14087 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14088 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14089 | requests[0].url = GURL("https://www.example.com/"); |
| 14090 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14091 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14092 | |
| 14093 | requests[1].url = GURL("http://www.example.com/"); |
| 14094 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14095 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14096 | |
| 14097 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14098 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14099 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14100 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14101 | |
| 14102 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14103 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14104 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14105 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14106 | |
| 14107 | // Complete the SSL handshake, which should abort due to requiring a |
| 14108 | // client certificate. |
| 14109 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14110 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14111 | |
| 14112 | // Indicate that no certificate should be supplied. From the perspective |
| 14113 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14114 | // certificate, so this is the same as supply a |
| 14115 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14116 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14117 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14118 | |
| 14119 | // Ensure the certificate was added to the client auth cache before |
| 14120 | // allowing the connection to continue restarting. |
| 14121 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14122 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14123 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14124 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14125 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14126 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 14127 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14128 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14129 | HostPortPair("www.example.com", 443), &client_cert, |
| 14130 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14131 | |
| 14132 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 14133 | // then consume ssl_data3, which should also fail. The result code is |
| 14134 | // checked against what ssl_data3 should return. |
| 14135 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14136 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14137 | |
| 14138 | // Now that the new handshake has failed, ensure that the client |
| 14139 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14140 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14141 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14142 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14143 | HostPortPair("www.example.com", 443), &client_cert, |
| 14144 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14145 | } |
| 14146 | } |
| 14147 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14148 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14149 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14150 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14151 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14152 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14153 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14154 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14155 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14156 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14157 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14158 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14159 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14160 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14161 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14162 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14163 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14164 | SpdySerializedFrame host1_resp_body( |
| 14165 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14166 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14167 | SpdySerializedFrame host2_resp_body( |
| 14168 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14169 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14170 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14171 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14172 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14173 | }; |
| 14174 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14175 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14176 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14177 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14178 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14179 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14180 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14181 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14182 | HttpRequestInfo request1; |
| 14183 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14184 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14185 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14186 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14187 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14188 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14189 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14190 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14191 | |
| 14192 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14193 | ASSERT_TRUE(response); |
| 14194 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14195 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14196 | |
| 14197 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14198 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14199 | EXPECT_EQ("hello!", response_data); |
| 14200 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14201 | // Preload mail.example.com into HostCache. |
| 14202 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 14203 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14204 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14205 | std::unique_ptr<HostResolver::Request> request; |
| 14206 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14207 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14208 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14209 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14210 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14211 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14212 | |
| 14213 | HttpRequestInfo request2; |
| 14214 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14215 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14216 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14217 | HttpNetworkTransaction trans2(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 | rv = trans2.Start(&request2, 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 | response = trans2.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 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14228 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14229 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14230 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14231 | } |
| 14232 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14233 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14234 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14235 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14236 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14237 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14238 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14239 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14240 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14241 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14242 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14243 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14244 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14245 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14246 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14247 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14248 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14249 | SpdySerializedFrame host1_resp_body( |
| 14250 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14251 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14252 | SpdySerializedFrame host2_resp_body( |
| 14253 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14254 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14255 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14256 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14257 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14258 | }; |
| 14259 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14260 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14261 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14262 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14263 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14264 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14265 | |
| 14266 | TestCompletionCallback callback; |
| 14267 | HttpRequestInfo request1; |
| 14268 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14269 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14270 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14271 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14272 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14273 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14274 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14275 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14276 | |
| 14277 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14278 | ASSERT_TRUE(response); |
| 14279 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14280 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14281 | |
| 14282 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14283 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14284 | EXPECT_EQ("hello!", response_data); |
| 14285 | |
| 14286 | HttpRequestInfo request2; |
| 14287 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14288 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14289 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14290 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14291 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14292 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14293 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14294 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14295 | |
| 14296 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14297 | ASSERT_TRUE(response); |
| 14298 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14299 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14300 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14301 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14302 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14303 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14304 | } |
| 14305 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14306 | // Regression test for https://crbug.com/546991. |
| 14307 | // The server might not be able to serve an IP pooled request, and might send a |
| 14308 | // 421 Misdirected Request response status to indicate this. |
| 14309 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 14310 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 14311 | // Two hosts resolve to the same IP address. |
| 14312 | const std::string ip_addr = "1.2.3.4"; |
| 14313 | IPAddress ip; |
| 14314 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14315 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14316 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14317 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14318 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14319 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14320 | |
| 14321 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14322 | |
| 14323 | // Two requests on the first connection. |
| 14324 | SpdySerializedFrame req1( |
| 14325 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14326 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14327 | SpdySerializedFrame req2( |
| 14328 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14329 | SpdySerializedFrame rst( |
| 14330 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14331 | MockWrite writes1[] = { |
| 14332 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14333 | CreateMockWrite(rst, 6), |
| 14334 | }; |
| 14335 | |
| 14336 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14337 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14338 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14339 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14340 | response_headers[kHttp2StatusHeader] = "421"; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14341 | SpdySerializedFrame resp2( |
| 14342 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 14343 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14344 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14345 | |
| 14346 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14347 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14348 | arraysize(writes1)); |
| 14349 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14350 | |
| 14351 | AddSSLSocketData(); |
| 14352 | |
| 14353 | // Retry the second request on a second connection. |
| 14354 | SpdyTestUtil spdy_util2; |
| 14355 | SpdySerializedFrame req3( |
| 14356 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14357 | MockWrite writes2[] = { |
| 14358 | CreateMockWrite(req3, 0), |
| 14359 | }; |
| 14360 | |
| 14361 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14362 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14363 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14364 | MockRead(ASYNC, 0, 3)}; |
| 14365 | |
| 14366 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14367 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14368 | arraysize(writes2)); |
| 14369 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14370 | |
| 14371 | AddSSLSocketData(); |
| 14372 | |
| 14373 | // Preload mail.example.org into HostCache. |
| 14374 | HostPortPair host_port("mail.example.org", 443); |
| 14375 | HostResolver::RequestInfo resolve_info(host_port); |
| 14376 | AddressList ignored; |
| 14377 | std::unique_ptr<HostResolver::Request> request; |
| 14378 | TestCompletionCallback callback; |
| 14379 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14380 | &ignored, callback.callback(), |
| 14381 | &request, NetLogWithSource()); |
| 14382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14383 | rv = callback.WaitForResult(); |
| 14384 | EXPECT_THAT(rv, IsOk()); |
| 14385 | |
| 14386 | HttpRequestInfo request1; |
| 14387 | request1.method = "GET"; |
| 14388 | request1.url = GURL("https://www.example.org/"); |
| 14389 | request1.load_flags = 0; |
| 14390 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14391 | |
| 14392 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14394 | rv = callback.WaitForResult(); |
| 14395 | EXPECT_THAT(rv, IsOk()); |
| 14396 | |
| 14397 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14398 | ASSERT_TRUE(response); |
| 14399 | ASSERT_TRUE(response->headers); |
| 14400 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14401 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14402 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14403 | std::string response_data; |
| 14404 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14405 | EXPECT_EQ("hello!", response_data); |
| 14406 | |
| 14407 | HttpRequestInfo request2; |
| 14408 | request2.method = "GET"; |
| 14409 | request2.url = GURL("https://mail.example.org/"); |
| 14410 | request2.load_flags = 0; |
| 14411 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14412 | |
| 14413 | BoundTestNetLog log; |
| 14414 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14415 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14416 | rv = callback.WaitForResult(); |
| 14417 | EXPECT_THAT(rv, IsOk()); |
| 14418 | |
| 14419 | response = trans2.GetResponseInfo(); |
| 14420 | ASSERT_TRUE(response); |
| 14421 | ASSERT_TRUE(response->headers); |
| 14422 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14423 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14424 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14425 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14426 | EXPECT_EQ("hello!", response_data); |
| 14427 | |
| 14428 | TestNetLogEntry::List entries; |
| 14429 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14430 | ExpectLogContainsSomewhere( |
| 14431 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14432 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14433 | } |
| 14434 | |
| 14435 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14436 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14437 | // portions of the response. |
| 14438 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14439 | // Two hosts resolve to the same IP address. |
| 14440 | const std::string ip_addr = "1.2.3.4"; |
| 14441 | IPAddress ip; |
| 14442 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14443 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14444 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14445 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14446 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14447 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14448 | |
| 14449 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14450 | |
| 14451 | // Two requests on the first connection. |
| 14452 | SpdySerializedFrame req1( |
| 14453 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14454 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14455 | SpdySerializedFrame req2( |
| 14456 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14457 | SpdySerializedFrame rst( |
| 14458 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14459 | MockWrite writes1[] = { |
| 14460 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14461 | CreateMockWrite(rst, 6), |
| 14462 | }; |
| 14463 | |
| 14464 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14465 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14466 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14467 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14468 | response_headers[kHttp2StatusHeader] = "421"; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14469 | SpdySerializedFrame resp2( |
| 14470 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14471 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14472 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14473 | |
| 14474 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14475 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14476 | arraysize(writes1)); |
| 14477 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14478 | |
| 14479 | AddSSLSocketData(); |
| 14480 | |
| 14481 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14482 | // Retry again. |
| 14483 | SpdyTestUtil spdy_util2; |
| 14484 | SpdySerializedFrame req3( |
| 14485 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14486 | MockWrite writes2[] = { |
| 14487 | CreateMockWrite(req3, 0), |
| 14488 | }; |
| 14489 | |
| 14490 | SpdySerializedFrame resp3( |
| 14491 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 14492 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14493 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14494 | MockRead(ASYNC, 0, 3)}; |
| 14495 | |
| 14496 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14497 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14498 | arraysize(writes2)); |
| 14499 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14500 | |
| 14501 | AddSSLSocketData(); |
| 14502 | |
| 14503 | // Preload mail.example.org into HostCache. |
| 14504 | HostPortPair host_port("mail.example.org", 443); |
| 14505 | HostResolver::RequestInfo resolve_info(host_port); |
| 14506 | AddressList ignored; |
| 14507 | std::unique_ptr<HostResolver::Request> request; |
| 14508 | TestCompletionCallback callback; |
| 14509 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14510 | &ignored, callback.callback(), |
| 14511 | &request, NetLogWithSource()); |
| 14512 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14513 | rv = callback.WaitForResult(); |
| 14514 | EXPECT_THAT(rv, IsOk()); |
| 14515 | |
| 14516 | HttpRequestInfo request1; |
| 14517 | request1.method = "GET"; |
| 14518 | request1.url = GURL("https://www.example.org/"); |
| 14519 | request1.load_flags = 0; |
| 14520 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14521 | |
| 14522 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14523 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14524 | rv = callback.WaitForResult(); |
| 14525 | EXPECT_THAT(rv, IsOk()); |
| 14526 | |
| 14527 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14528 | ASSERT_TRUE(response); |
| 14529 | ASSERT_TRUE(response->headers); |
| 14530 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14531 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14532 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14533 | std::string response_data; |
| 14534 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14535 | EXPECT_EQ("hello!", response_data); |
| 14536 | |
| 14537 | HttpRequestInfo request2; |
| 14538 | request2.method = "GET"; |
| 14539 | request2.url = GURL("https://mail.example.org/"); |
| 14540 | request2.load_flags = 0; |
| 14541 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14542 | |
| 14543 | BoundTestNetLog log; |
| 14544 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14545 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14546 | rv = callback.WaitForResult(); |
| 14547 | EXPECT_THAT(rv, IsOk()); |
| 14548 | |
| 14549 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14550 | // caller. |
| 14551 | response = trans2.GetResponseInfo(); |
| 14552 | ASSERT_TRUE(response); |
| 14553 | ASSERT_TRUE(response->headers); |
| 14554 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14555 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14556 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14557 | EXPECT_TRUE(response->ssl_info.cert); |
| 14558 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14559 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14560 | } |
| 14561 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14562 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14563 | public: |
| 14564 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14565 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14566 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14567 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14568 | int ResolveFromCache(const RequestInfo& info, |
| 14569 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14570 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14571 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14572 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14573 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14574 | return rv; |
| 14575 | } |
| 14576 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14577 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14578 | const HostPortPair host_port_; |
| 14579 | }; |
| 14580 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14581 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14582 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14583 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14584 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14585 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14586 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14587 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14588 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14589 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14590 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14591 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14592 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14593 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14594 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14595 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14596 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14597 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14598 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14599 | SpdySerializedFrame host1_resp_body( |
| 14600 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14601 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14602 | SpdySerializedFrame host2_resp_body( |
| 14603 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14604 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14605 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14606 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14607 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14608 | }; |
| 14609 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14610 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14611 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14612 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14613 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14614 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14615 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14616 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14617 | HttpRequestInfo request1; |
| 14618 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14619 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14620 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14621 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14623 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14625 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14626 | |
| 14627 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14628 | ASSERT_TRUE(response); |
| 14629 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14630 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14631 | |
| 14632 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14633 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14634 | EXPECT_EQ("hello!", response_data); |
| 14635 | |
| 14636 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14637 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14638 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14639 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14640 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14641 | &ignored, callback.callback(), |
| 14642 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14644 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14645 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14646 | |
| 14647 | HttpRequestInfo request2; |
| 14648 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14649 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14650 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14651 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14652 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14653 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14654 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14655 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14656 | |
| 14657 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14658 | ASSERT_TRUE(response); |
| 14659 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14660 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14661 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14662 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14663 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14664 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14665 | } |
| 14666 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14667 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14668 | const std::string https_url = "https://www.example.org:8080/"; |
| 14669 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14670 | |
| 14671 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14672 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14673 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14674 | |
| 14675 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14676 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14677 | }; |
| 14678 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14679 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14680 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14681 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14682 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14683 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14684 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14685 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14686 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14687 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14688 | |
| 14689 | // HTTP GET for the HTTP URL |
| 14690 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14691 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14692 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14693 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14694 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14695 | }; |
| 14696 | |
| 14697 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14698 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 14699 | MockRead(ASYNC, 2, "hello"), |
| 14700 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14701 | }; |
| 14702 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14703 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14704 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14705 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14706 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14707 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14708 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14709 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14710 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14711 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14713 | |
| 14714 | // Start the first transaction to set up the SpdySession |
| 14715 | HttpRequestInfo request1; |
| 14716 | request1.method = "GET"; |
| 14717 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14718 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14719 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14720 | TestCompletionCallback callback1; |
| 14721 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14722 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14723 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14724 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14725 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14726 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14727 | |
| 14728 | // Now, start the HTTP request |
| 14729 | HttpRequestInfo request2; |
| 14730 | request2.method = "GET"; |
| 14731 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14732 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14733 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14734 | TestCompletionCallback callback2; |
| 14735 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14736 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14737 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14738 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14739 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14740 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14741 | } |
| 14742 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14743 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 14744 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14745 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14746 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14747 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14748 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14749 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14750 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14751 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14752 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14753 | |
| 14754 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14755 | // negotiated. |
| 14756 | StaticSocketDataProvider data; |
| 14757 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14758 | |
| 14759 | // 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] | 14760 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14761 | // mocked. This way the request relies on the alternate Job. |
| 14762 | StaticSocketDataProvider data_refused; |
| 14763 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14764 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14765 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14766 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14767 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14768 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14769 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14770 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14771 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14772 | http_server_properties->SetHttp2AlternativeService( |
| 14773 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14774 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14775 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14776 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14777 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14778 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14779 | TestCompletionCallback callback; |
| 14780 | |
| 14781 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14782 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14783 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14784 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14785 | } |
| 14786 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14787 | // 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] | 14788 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14789 | // succeeds, the request should succeed, even if the latter fails because |
| 14790 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14791 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14792 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14793 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14794 | |
| 14795 | // Negotiate HTTP/1.1 with alternative. |
| 14796 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14797 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14798 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 14799 | |
| 14800 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14801 | // negotiated. |
| 14802 | StaticSocketDataProvider data; |
| 14803 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14804 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14805 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14806 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14807 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14808 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 14809 | |
| 14810 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14811 | MockWrite("GET / HTTP/1.1\r\n" |
| 14812 | "Host: www.example.org\r\n" |
| 14813 | "Connection: keep-alive\r\n\r\n"), |
| 14814 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14815 | "Host: www.example.org\r\n" |
| 14816 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14817 | }; |
| 14818 | |
| 14819 | MockRead http_reads[] = { |
| 14820 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14821 | MockRead("Content-Type: text/html\r\n"), |
| 14822 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14823 | MockRead("foobar"), |
| 14824 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14825 | MockRead("Content-Type: text/html\r\n"), |
| 14826 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14827 | MockRead("another"), |
| 14828 | }; |
| 14829 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14830 | http_writes, arraysize(http_writes)); |
| 14831 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14832 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14833 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14835 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14836 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14837 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14838 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14839 | http_server_properties->SetHttp2AlternativeService( |
| 14840 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14841 | |
| 14842 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14843 | HttpRequestInfo request1; |
| 14844 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14845 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14846 | request1.load_flags = 0; |
| 14847 | TestCompletionCallback callback1; |
| 14848 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14849 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14850 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14851 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14852 | |
| 14853 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14854 | ASSERT_TRUE(response1); |
| 14855 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14856 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14857 | |
| 14858 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14859 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14860 | EXPECT_EQ("foobar", response_data1); |
| 14861 | |
| 14862 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14863 | // for alternative service. |
| 14864 | EXPECT_TRUE( |
| 14865 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14866 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14867 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14868 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14869 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14870 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14871 | HttpRequestInfo request2; |
| 14872 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14873 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14874 | request2.load_flags = 0; |
| 14875 | TestCompletionCallback callback2; |
| 14876 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14877 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14878 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14879 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14880 | |
| 14881 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14882 | ASSERT_TRUE(response2); |
| 14883 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14884 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14885 | |
| 14886 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14887 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14888 | EXPECT_EQ("another", response_data2); |
| 14889 | } |
| 14890 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14891 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14892 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14893 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14894 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14895 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14896 | HostPortPair alternative("alternative.example.org", 443); |
| 14897 | std::string origin_url = "https://origin.example.org:443"; |
| 14898 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14899 | |
| 14900 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14901 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14902 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14903 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14904 | |
| 14905 | // HTTP/1.1 data for |request1| and |request2|. |
| 14906 | MockWrite http_writes[] = { |
| 14907 | MockWrite( |
| 14908 | "GET / HTTP/1.1\r\n" |
| 14909 | "Host: alternative.example.org\r\n" |
| 14910 | "Connection: keep-alive\r\n\r\n"), |
| 14911 | MockWrite( |
| 14912 | "GET / HTTP/1.1\r\n" |
| 14913 | "Host: alternative.example.org\r\n" |
| 14914 | "Connection: keep-alive\r\n\r\n"), |
| 14915 | }; |
| 14916 | |
| 14917 | MockRead http_reads[] = { |
| 14918 | MockRead( |
| 14919 | "HTTP/1.1 200 OK\r\n" |
| 14920 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14921 | "Content-Length: 40\r\n\r\n" |
| 14922 | "first HTTP/1.1 response from alternative"), |
| 14923 | MockRead( |
| 14924 | "HTTP/1.1 200 OK\r\n" |
| 14925 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14926 | "Content-Length: 41\r\n\r\n" |
| 14927 | "second HTTP/1.1 response from alternative"), |
| 14928 | }; |
| 14929 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14930 | http_writes, arraysize(http_writes)); |
| 14931 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14932 | |
| 14933 | // This test documents that an alternate Job should not pool to an already |
| 14934 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14935 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14936 | StaticSocketDataProvider data_refused; |
| 14937 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14938 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14939 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14940 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14941 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14942 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14943 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14944 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14945 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14946 | http_server_properties->SetHttp2AlternativeService( |
| 14947 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14948 | |
| 14949 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14950 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14951 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14952 | request1.method = "GET"; |
| 14953 | request1.url = GURL(alternative_url); |
| 14954 | request1.load_flags = 0; |
| 14955 | TestCompletionCallback callback1; |
| 14956 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14957 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14958 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14959 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14960 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14961 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14962 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14963 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14964 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14965 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14966 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14967 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14968 | |
| 14969 | // Request for origin.example.org, which has an alternative service. This |
| 14970 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14971 | // 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] | 14972 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14973 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14974 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14975 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14976 | request2.method = "GET"; |
| 14977 | request2.url = GURL(origin_url); |
| 14978 | request2.load_flags = 0; |
| 14979 | TestCompletionCallback callback2; |
| 14980 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14981 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14982 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14983 | |
| 14984 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14985 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14986 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14987 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14988 | request3.method = "GET"; |
| 14989 | request3.url = GURL(alternative_url); |
| 14990 | request3.load_flags = 0; |
| 14991 | TestCompletionCallback callback3; |
| 14992 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14993 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14994 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14995 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14996 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14997 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14998 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14999 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15000 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 15001 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15002 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15003 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 15004 | } |
| 15005 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15006 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15007 | const std::string https_url = "https://www.example.org:8080/"; |
| 15008 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15009 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15010 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15011 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15012 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15013 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15014 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15015 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15016 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15017 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15018 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15019 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15020 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 15021 | |
| 15022 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 15023 | SpdyHeaderBlock req2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 15024 | req2_block[kHttp2MethodHeader] = "GET"; |
| 15025 | req2_block[kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 15026 | req2_block[kHttp2SchemeHeader] = "http"; |
| 15027 | req2_block[kHttp2PathHeader] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15028 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15029 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15030 | |
| 15031 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15032 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 15033 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15034 | }; |
| 15035 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15036 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15037 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15038 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15039 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15040 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 15041 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15042 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15043 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15044 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15045 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15046 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15047 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15048 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15049 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15050 | CreateMockRead(wrapped_resp1, 4), |
| 15051 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15052 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15053 | CreateMockRead(resp2, 8), |
| 15054 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15055 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 15056 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15057 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15058 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15059 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15060 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15061 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15062 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15063 | session_deps_.proxy_service = |
| 15064 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15065 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15066 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15067 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15068 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15069 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15070 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15071 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15072 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15073 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15074 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15075 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15076 | |
| 15077 | // Start the first transaction to set up the SpdySession |
| 15078 | HttpRequestInfo request1; |
| 15079 | request1.method = "GET"; |
| 15080 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15081 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15082 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15083 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15084 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15085 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15086 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15087 | data1.RunUntilPaused(); |
| 15088 | base::RunLoop().RunUntilIdle(); |
| 15089 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15090 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15091 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15092 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15093 | LoadTimingInfo load_timing_info1; |
| 15094 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 15095 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 15096 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15097 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15098 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15099 | HttpRequestInfo request2; |
| 15100 | request2.method = "GET"; |
| 15101 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15102 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15103 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15104 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15105 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15106 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15107 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15108 | data1.RunUntilPaused(); |
| 15109 | base::RunLoop().RunUntilIdle(); |
| 15110 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15111 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15112 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15113 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15114 | |
| 15115 | LoadTimingInfo load_timing_info2; |
| 15116 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 15117 | // The established SPDY sessions is considered reused by the HTTP request. |
| 15118 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 15119 | // HTTP requests over a SPDY session should have a different connection |
| 15120 | // socket_log_id than requests over a tunnel. |
| 15121 | 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] | 15122 | } |
| 15123 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15124 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 15125 | // that we do not pool other origins that resolve to the same IP when |
| 15126 | // the certificate does not match the new origin. |
| 15127 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15128 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15129 | const std::string url1 = "http://www.example.org/"; |
| 15130 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15131 | const std::string ip_addr = "1.2.3.4"; |
| 15132 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15133 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15134 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15135 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15136 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 15137 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15138 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15139 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15140 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15141 | |
| 15142 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15143 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15144 | }; |
| 15145 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15146 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15147 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15148 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15149 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 15150 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15151 | }; |
| 15152 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15153 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15154 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 15155 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 15156 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15157 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15158 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15159 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15160 | |
| 15161 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15162 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15163 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15164 | |
| 15165 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15166 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15167 | }; |
| 15168 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15169 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15170 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 15171 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15172 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15173 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15174 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15175 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15176 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15177 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15178 | |
| 15179 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 15180 | // all others direct. |
| 15181 | ProxyConfig proxy_config; |
| 15182 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15183 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 15184 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15185 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15186 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15187 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15188 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15189 | // Load a valid cert. Note, that this does not need to |
| 15190 | // be valid for proxy because the MockSSLClientSocket does |
| 15191 | // not actually verify it. But SpdySession will use this |
| 15192 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 15193 | ssl1.ssl_info.cert = |
| 15194 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 15195 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15197 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15198 | |
| 15199 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15200 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15202 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15203 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15204 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15205 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15206 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15207 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15208 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15209 | |
| 15210 | // Start the first transaction to set up the SpdySession |
| 15211 | HttpRequestInfo request1; |
| 15212 | request1.method = "GET"; |
| 15213 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15214 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15215 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15216 | TestCompletionCallback callback1; |
| 15217 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15218 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15219 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15220 | data1.RunUntilPaused(); |
| 15221 | base::RunLoop().RunUntilIdle(); |
| 15222 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15223 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15224 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15225 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15226 | |
| 15227 | // Now, start the HTTP request |
| 15228 | HttpRequestInfo request2; |
| 15229 | request2.method = "GET"; |
| 15230 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15231 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15232 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15233 | TestCompletionCallback callback2; |
| 15234 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15235 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15236 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15237 | |
| 15238 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15239 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15240 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15241 | } |
| 15242 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15243 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 15244 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 15245 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 15246 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15247 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15248 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15249 | |
| 15250 | MockRead reads1[] = { |
| 15251 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 15252 | }; |
| 15253 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15254 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15255 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15256 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15257 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15258 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15259 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15260 | }; |
| 15261 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15262 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15263 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15264 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15265 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 15266 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15267 | }; |
| 15268 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15269 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15270 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15271 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15272 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15273 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15274 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15275 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15276 | |
| 15277 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15278 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15279 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15280 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15281 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15282 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15283 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15284 | |
| 15285 | // Start the first transaction to set up the SpdySession and verify that |
| 15286 | // connection was closed. |
| 15287 | HttpRequestInfo request1; |
| 15288 | request1.method = "GET"; |
| 15289 | request1.url = GURL(https_url); |
| 15290 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15291 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15292 | TestCompletionCallback callback1; |
| 15293 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15294 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15295 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15296 | |
| 15297 | // Now, start the second request and make sure it succeeds. |
| 15298 | HttpRequestInfo request2; |
| 15299 | request2.method = "GET"; |
| 15300 | request2.url = GURL(https_url); |
| 15301 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15302 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15303 | TestCompletionCallback callback2; |
| 15304 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15305 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15306 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15307 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15308 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15309 | } |
| 15310 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15311 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15312 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15313 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15314 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15315 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15316 | |
| 15317 | // Use two different hosts with different IPs so they don't get pooled. |
| 15318 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 15319 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15320 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15321 | |
| 15322 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15323 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15324 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15325 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15326 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15327 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15328 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15329 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15330 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15331 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15332 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15333 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15334 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15335 | SpdySerializedFrame host1_resp_body( |
| 15336 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15337 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15338 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15339 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15340 | }; |
| 15341 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15342 | // Use a separate test instance for the separate SpdySession that will be |
| 15343 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15344 | SpdyTestUtil spdy_util_2; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15345 | auto spdy1_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15346 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 15347 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15348 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 15349 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15350 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15351 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15352 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15353 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15354 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15355 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15356 | SpdySerializedFrame host2_resp_body( |
| 15357 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15358 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15359 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15360 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15361 | }; |
| 15362 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15363 | auto spdy2_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15364 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 15365 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15366 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 15367 | |
| 15368 | MockWrite http_write[] = { |
| 15369 | MockWrite("GET / HTTP/1.1\r\n" |
| 15370 | "Host: www.a.com\r\n" |
| 15371 | "Connection: keep-alive\r\n\r\n"), |
| 15372 | }; |
| 15373 | |
| 15374 | MockRead http_read[] = { |
| 15375 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15376 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15377 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15378 | MockRead("hello!"), |
| 15379 | }; |
| 15380 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 15381 | http_write, arraysize(http_write)); |
| 15382 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15383 | |
| 15384 | HostPortPair host_port_pair_a("www.a.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15385 | SpdySessionKey spdy_session_key_a(host_port_pair_a, ProxyServer::Direct(), |
| 15386 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15387 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15388 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15389 | |
| 15390 | TestCompletionCallback callback; |
| 15391 | HttpRequestInfo request1; |
| 15392 | request1.method = "GET"; |
| 15393 | request1.url = GURL("https://www.a.com/"); |
| 15394 | request1.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15395 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15396 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15397 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15398 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15399 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15400 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15401 | |
| 15402 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15403 | ASSERT_TRUE(response); |
| 15404 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15405 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15406 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15407 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15408 | |
| 15409 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15410 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15411 | EXPECT_EQ("hello!", response_data); |
| 15412 | trans.reset(); |
| 15413 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15414 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15415 | |
| 15416 | HostPortPair host_port_pair_b("www.b.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15417 | SpdySessionKey spdy_session_key_b(host_port_pair_b, ProxyServer::Direct(), |
| 15418 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15419 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15420 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15421 | HttpRequestInfo request2; |
| 15422 | request2.method = "GET"; |
| 15423 | request2.url = GURL("https://www.b.com/"); |
| 15424 | request2.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15425 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15426 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15427 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15428 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15429 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15430 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15431 | |
| 15432 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15433 | ASSERT_TRUE(response); |
| 15434 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15435 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15436 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15437 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15438 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15439 | EXPECT_EQ("hello!", response_data); |
| 15440 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15441 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15442 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15443 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15444 | |
| 15445 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15446 | SpdySessionKey spdy_session_key_a1(host_port_pair_a1, ProxyServer::Direct(), |
| 15447 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15448 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15449 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15450 | HttpRequestInfo request3; |
| 15451 | request3.method = "GET"; |
| 15452 | request3.url = GURL("http://www.a.com/"); |
| 15453 | request3.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15454 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15455 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15456 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15457 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15458 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15459 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15460 | |
| 15461 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15462 | ASSERT_TRUE(response); |
| 15463 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15464 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15465 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15466 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15467 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15468 | EXPECT_EQ("hello!", response_data); |
| 15469 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15470 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15471 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15472 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15473 | } |
| 15474 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15475 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15476 | HttpRequestInfo request; |
| 15477 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15478 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15479 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15480 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15481 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15482 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15483 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15484 | StaticSocketDataProvider data; |
| 15485 | data.set_connect_data(mock_connect); |
| 15486 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15487 | |
| 15488 | TestCompletionCallback callback; |
| 15489 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15490 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15491 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15492 | |
| 15493 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15494 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15495 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15496 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15497 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15498 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15499 | |
| 15500 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15501 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15502 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15503 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15504 | |
| 15505 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15506 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15507 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15508 | } |
| 15509 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15510 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15511 | HttpRequestInfo request; |
| 15512 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15513 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15514 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15516 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15517 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15518 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15519 | StaticSocketDataProvider data; |
| 15520 | data.set_connect_data(mock_connect); |
| 15521 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15522 | |
| 15523 | TestCompletionCallback callback; |
| 15524 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15525 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15526 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15527 | |
| 15528 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15529 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15530 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15531 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15532 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15533 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15534 | |
| 15535 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15536 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15537 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15538 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15539 | |
| 15540 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15541 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15542 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15543 | } |
| 15544 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15545 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15546 | HttpRequestInfo request; |
| 15547 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15548 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15549 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15550 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15551 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15552 | |
| 15553 | MockWrite data_writes[] = { |
| 15554 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15555 | }; |
| 15556 | MockRead data_reads[] = { |
| 15557 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15558 | }; |
| 15559 | |
| 15560 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15561 | data_writes, arraysize(data_writes)); |
| 15562 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15563 | |
| 15564 | TestCompletionCallback callback; |
| 15565 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15566 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15567 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15568 | |
| 15569 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15570 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15571 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15572 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15573 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15574 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15575 | } |
| 15576 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15577 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15578 | HttpRequestInfo request; |
| 15579 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15580 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15581 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15582 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15583 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15584 | |
| 15585 | MockWrite data_writes[] = { |
| 15586 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 15587 | }; |
| 15588 | MockRead data_reads[] = { |
| 15589 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15590 | }; |
| 15591 | |
| 15592 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15593 | data_writes, arraysize(data_writes)); |
| 15594 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15595 | |
| 15596 | TestCompletionCallback callback; |
| 15597 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15598 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15599 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15600 | |
| 15601 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15602 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15603 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15604 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15605 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15606 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15607 | } |
| 15608 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15609 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15610 | HttpRequestInfo request; |
| 15611 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15612 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15613 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15614 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15615 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15616 | |
| 15617 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15618 | MockWrite( |
| 15619 | "GET / HTTP/1.1\r\n" |
| 15620 | "Host: www.example.org\r\n" |
| 15621 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15622 | }; |
| 15623 | MockRead data_reads[] = { |
| 15624 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15625 | }; |
| 15626 | |
| 15627 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15628 | data_writes, arraysize(data_writes)); |
| 15629 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15630 | |
| 15631 | TestCompletionCallback callback; |
| 15632 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15633 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15634 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15635 | |
| 15636 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15637 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15638 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15639 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15640 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15641 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15642 | } |
| 15643 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15644 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15645 | HttpRequestInfo request; |
| 15646 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15647 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15648 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15649 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15650 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15651 | |
| 15652 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15653 | MockWrite( |
| 15654 | "GET / HTTP/1.1\r\n" |
| 15655 | "Host: www.example.org\r\n" |
| 15656 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15657 | }; |
| 15658 | MockRead data_reads[] = { |
| 15659 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 15660 | }; |
| 15661 | |
| 15662 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15663 | data_writes, arraysize(data_writes)); |
| 15664 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15665 | |
| 15666 | TestCompletionCallback callback; |
| 15667 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15668 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15669 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15670 | |
| 15671 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15672 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15673 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15674 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15675 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15676 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15677 | } |
| 15678 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15679 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15680 | HttpRequestInfo request; |
| 15681 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15682 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15683 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 15684 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15685 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15686 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15687 | |
| 15688 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15689 | MockWrite( |
| 15690 | "GET / HTTP/1.1\r\n" |
| 15691 | "Host: www.example.org\r\n" |
| 15692 | "Connection: keep-alive\r\n" |
| 15693 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15694 | }; |
| 15695 | MockRead data_reads[] = { |
| 15696 | MockRead("HTTP/1.1 200 OK\r\n" |
| 15697 | "Content-Length: 5\r\n\r\n" |
| 15698 | "hello"), |
| 15699 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 15700 | }; |
| 15701 | |
| 15702 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15703 | data_writes, arraysize(data_writes)); |
| 15704 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15705 | |
| 15706 | TestCompletionCallback callback; |
| 15707 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15708 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15709 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15710 | |
| 15711 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15712 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15713 | |
| 15714 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15715 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15716 | std::string foo; |
| 15717 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 15718 | EXPECT_EQ("bar", foo); |
| 15719 | } |
| 15720 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15721 | namespace { |
| 15722 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15723 | // Fake HttpStream that simply records calls to SetPriority(). |
| 15724 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15725 | public base::SupportsWeakPtr<FakeStream> { |
| 15726 | public: |
| 15727 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15728 | ~FakeStream() override = default; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15729 | |
| 15730 | RequestPriority priority() const { return priority_; } |
| 15731 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15732 | int InitializeStream(const HttpRequestInfo* request_info, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 15733 | bool can_send_early, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15734 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15735 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15736 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15737 | return ERR_IO_PENDING; |
| 15738 | } |
| 15739 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15740 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15741 | HttpResponseInfo* response, |
| 15742 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15743 | ADD_FAILURE(); |
| 15744 | return ERR_UNEXPECTED; |
| 15745 | } |
| 15746 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15747 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15748 | ADD_FAILURE(); |
| 15749 | return ERR_UNEXPECTED; |
| 15750 | } |
| 15751 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15752 | int ReadResponseBody(IOBuffer* buf, |
| 15753 | int buf_len, |
| 15754 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15755 | ADD_FAILURE(); |
| 15756 | return ERR_UNEXPECTED; |
| 15757 | } |
| 15758 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15759 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15760 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15761 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15762 | ADD_FAILURE(); |
| 15763 | return false; |
| 15764 | } |
| 15765 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15766 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15767 | ADD_FAILURE(); |
| 15768 | return false; |
| 15769 | } |
| 15770 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15771 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15772 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15773 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15774 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15775 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 15776 | ADD_FAILURE(); |
| 15777 | return 0; |
| 15778 | } |
| 15779 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15780 | int64_t GetTotalSentBytes() const override { |
| 15781 | ADD_FAILURE(); |
| 15782 | return 0; |
| 15783 | } |
| 15784 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15785 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15786 | ADD_FAILURE(); |
| 15787 | return false; |
| 15788 | } |
| 15789 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15790 | bool GetAlternativeService( |
| 15791 | AlternativeService* alternative_service) const override { |
| 15792 | ADD_FAILURE(); |
| 15793 | return false; |
| 15794 | } |
| 15795 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15796 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 15797 | |
| 15798 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15799 | ADD_FAILURE(); |
| 15800 | } |
| 15801 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15802 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15803 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15804 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15805 | TokenBindingType tb_type, |
| 15806 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15807 | ADD_FAILURE(); |
| 15808 | return ERR_NOT_IMPLEMENTED; |
| 15809 | } |
| 15810 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15811 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15812 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15813 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15814 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15815 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15816 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15817 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15818 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 15819 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 15820 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15821 | private: |
| 15822 | RequestPriority priority_; |
| 15823 | |
| 15824 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15825 | }; |
| 15826 | |
| 15827 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15828 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15829 | class FakeStreamRequest : public HttpStreamRequest, |
| 15830 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15831 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15832 | FakeStreamRequest(RequestPriority priority, |
| 15833 | HttpStreamRequest::Delegate* delegate) |
| 15834 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15835 | delegate_(delegate), |
| 15836 | websocket_stream_create_helper_(NULL) {} |
| 15837 | |
| 15838 | FakeStreamRequest(RequestPriority priority, |
| 15839 | HttpStreamRequest::Delegate* delegate, |
| 15840 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15841 | : priority_(priority), |
| 15842 | delegate_(delegate), |
| 15843 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15844 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15845 | ~FakeStreamRequest() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15846 | |
| 15847 | RequestPriority priority() const { return priority_; } |
| 15848 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15849 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15850 | websocket_stream_create_helper() const { |
| 15851 | return websocket_stream_create_helper_; |
| 15852 | } |
| 15853 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15854 | // Create a new FakeStream and pass it to the request's |
| 15855 | // delegate. Returns a weak pointer to the FakeStream. |
| 15856 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15857 | auto fake_stream = std::make_unique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15858 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15859 | // immediately delete |fake_stream|. |
| 15860 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 15861 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15862 | return weak_stream; |
| 15863 | } |
| 15864 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15865 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15866 | ADD_FAILURE(); |
| 15867 | return ERR_UNEXPECTED; |
| 15868 | } |
| 15869 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15870 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15871 | ADD_FAILURE(); |
| 15872 | return LoadState(); |
| 15873 | } |
| 15874 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15875 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15876 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15877 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15878 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15879 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15880 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15881 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15882 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15883 | const ConnectionAttempts& connection_attempts() const override { |
| 15884 | static ConnectionAttempts no_attempts; |
| 15885 | return no_attempts; |
| 15886 | } |
| 15887 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15888 | private: |
| 15889 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15890 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15891 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15892 | |
| 15893 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15894 | }; |
| 15895 | |
| 15896 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15897 | class FakeStreamFactory : public HttpStreamFactory { |
| 15898 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15899 | FakeStreamFactory() = default; |
| 15900 | ~FakeStreamFactory() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15901 | |
| 15902 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15903 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15904 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15905 | return last_stream_request_; |
| 15906 | } |
| 15907 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15908 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 15909 | const HttpRequestInfo& info, |
| 15910 | RequestPriority priority, |
| 15911 | const SSLConfig& server_ssl_config, |
| 15912 | const SSLConfig& proxy_ssl_config, |
| 15913 | HttpStreamRequest::Delegate* delegate, |
| 15914 | bool enable_ip_based_pooling, |
| 15915 | bool enable_alternative_services, |
| 15916 | const NetLogWithSource& net_log) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15917 | auto fake_request = std::make_unique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15918 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15919 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15920 | } |
| 15921 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15922 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15923 | const HttpRequestInfo& info, |
| 15924 | RequestPriority priority, |
| 15925 | const SSLConfig& server_ssl_config, |
| 15926 | const SSLConfig& proxy_ssl_config, |
| 15927 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15928 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15929 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15930 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15931 | NOTREACHED(); |
| 15932 | return nullptr; |
| 15933 | } |
| 15934 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15935 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15936 | const HttpRequestInfo& info, |
| 15937 | RequestPriority priority, |
| 15938 | const SSLConfig& server_ssl_config, |
| 15939 | const SSLConfig& proxy_ssl_config, |
| 15940 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15941 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15942 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15943 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15944 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15945 | auto fake_request = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15946 | std::make_unique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15947 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15948 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15949 | } |
| 15950 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15951 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15952 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15953 | ADD_FAILURE(); |
| 15954 | } |
| 15955 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15956 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15957 | ADD_FAILURE(); |
| 15958 | return NULL; |
| 15959 | } |
| 15960 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15961 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15962 | const std::string& parent_absolute_name) const override { |
| 15963 | ADD_FAILURE(); |
| 15964 | } |
| 15965 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15966 | private: |
| 15967 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15968 | |
| 15969 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15970 | }; |
| 15971 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15972 | // TODO(ricea): Maybe unify this with the one in |
| 15973 | // url_request_http_job_unittest.cc ? |
| 15974 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15975 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15976 | FakeWebSocketBasicHandshakeStream( |
| 15977 | std::unique_ptr<ClientSocketHandle> connection, |
| 15978 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15979 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15980 | |
| 15981 | // Fake implementation of HttpStreamBase methods. |
| 15982 | // This ends up being quite "real" because this object has to really send data |
| 15983 | // on the mock socket. It might be easier to use the real implementation, but |
| 15984 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15985 | // difficult. |
| 15986 | int InitializeStream(const HttpRequestInfo* request_info, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 15987 | bool can_send_early, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15988 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15989 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15990 | const CompletionCallback& callback) override { |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 15991 | state_.Initialize(request_info, can_send_early, priority, net_log, |
| 15992 | callback); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15993 | return OK; |
| 15994 | } |
| 15995 | |
| 15996 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15997 | HttpResponseInfo* response, |
| 15998 | const CompletionCallback& callback) override { |
| 15999 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 16000 | TRAFFIC_ANNOTATION_FOR_TESTS, response, |
| 16001 | callback); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16002 | } |
| 16003 | |
| 16004 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 16005 | return parser()->ReadResponseHeaders(callback); |
| 16006 | } |
| 16007 | |
| 16008 | int ReadResponseBody(IOBuffer* buf, |
| 16009 | int buf_len, |
| 16010 | const CompletionCallback& callback) override { |
| 16011 | NOTREACHED(); |
| 16012 | return ERR_IO_PENDING; |
| 16013 | } |
| 16014 | |
| 16015 | void Close(bool not_reusable) override { |
| 16016 | if (parser()) |
| 16017 | parser()->Close(true); |
| 16018 | } |
| 16019 | |
| 16020 | bool IsResponseBodyComplete() const override { |
| 16021 | NOTREACHED(); |
| 16022 | return false; |
| 16023 | } |
| 16024 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16025 | bool IsConnectionReused() const override { |
| 16026 | NOTREACHED(); |
| 16027 | return false; |
| 16028 | } |
| 16029 | void SetConnectionReused() override { NOTREACHED(); } |
| 16030 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 16031 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16032 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 16033 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16034 | NOTREACHED(); |
| 16035 | return 0; |
| 16036 | } |
| 16037 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 16038 | int64_t GetTotalSentBytes() const override { |
| 16039 | NOTREACHED(); |
| 16040 | return 0; |
| 16041 | } |
| 16042 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16043 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 16044 | NOTREACHED(); |
| 16045 | return false; |
| 16046 | } |
| 16047 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 16048 | bool GetAlternativeService( |
| 16049 | AlternativeService* alternative_service) const override { |
| 16050 | ADD_FAILURE(); |
| 16051 | return false; |
| 16052 | } |
| 16053 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 16054 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16055 | |
| 16056 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 16057 | NOTREACHED(); |
| 16058 | } |
| 16059 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16060 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 16061 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 16062 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 16063 | TokenBindingType tb_type, |
| 16064 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16065 | ADD_FAILURE(); |
| 16066 | return ERR_NOT_IMPLEMENTED; |
| 16067 | } |
| 16068 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16069 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 16070 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 16071 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 16072 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16073 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 16074 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16075 | HttpStream* RenewStreamForAuth() override { |
| 16076 | NOTREACHED(); |
| 16077 | return nullptr; |
| 16078 | } |
| 16079 | |
| 16080 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16081 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16082 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16083 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16084 | } |
| 16085 | |
| 16086 | private: |
| 16087 | HttpStreamParser* parser() const { return state_.parser(); } |
| 16088 | HttpBasicState state_; |
| 16089 | |
| 16090 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 16091 | }; |
| 16092 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16093 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 16094 | // worth doing. |
| 16095 | class FakeWebSocketStreamCreateHelper : |
| 16096 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 16097 | public: |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 16098 | std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16099 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 16100 | bool using_proxy) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16101 | return std::make_unique<FakeWebSocketBasicHandshakeStream>( |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 16102 | std::move(connection), using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16103 | } |
| 16104 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16105 | ~FakeWebSocketStreamCreateHelper() override = default; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16106 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16107 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16108 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16109 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16110 | } |
| 16111 | }; |
| 16112 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16113 | } // namespace |
| 16114 | |
| 16115 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 16116 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16117 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16119 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16120 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16121 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16122 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16123 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16124 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16125 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16126 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16127 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16128 | TestCompletionCallback callback; |
| 16129 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16130 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16131 | |
| 16132 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16133 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16134 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16135 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16136 | } |
| 16137 | |
| 16138 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16139 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16140 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16141 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16142 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16143 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16144 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16145 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16146 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16147 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16148 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16149 | TestCompletionCallback callback; |
| 16150 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16151 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16152 | |
| 16153 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16154 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16155 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16156 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16157 | |
| 16158 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16159 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16160 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 16161 | } |
| 16162 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16163 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16164 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16165 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16166 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16167 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16168 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16169 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16170 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16171 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16172 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16173 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16174 | TestCompletionCallback callback; |
| 16175 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16176 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16177 | |
| 16178 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16179 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16180 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16181 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16182 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16183 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 16184 | |
| 16185 | trans.SetPriority(LOWEST); |
| 16186 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 16187 | } |
| 16188 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16189 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16190 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 16191 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 16192 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16193 | std::string test_cases[] = {"ws://www.example.org/", |
| 16194 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16195 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16196 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16197 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16198 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 16199 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
Bence Béky | 8cae04e | 2018-01-15 18:37:06 | [diff] [blame] | 16200 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [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] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16204 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 16205 | &websocket_stream_create_helper); |
| 16206 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16207 | TestCompletionCallback callback; |
| 16208 | request.method = "GET"; |
| 16209 | request.url = GURL(test_cases[i]); |
| 16210 | |
| 16211 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16212 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16213 | |
| 16214 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16215 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16216 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16217 | EXPECT_EQ(&websocket_stream_create_helper, |
| 16218 | fake_request->websocket_stream_create_helper()); |
| 16219 | } |
| 16220 | } |
| 16221 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16222 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16223 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16224 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16225 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16226 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16227 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16228 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16229 | |
| 16230 | // Set up SSL request. |
| 16231 | |
| 16232 | HttpRequestInfo ssl_request; |
| 16233 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16234 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16235 | |
| 16236 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16237 | MockWrite( |
| 16238 | "GET / HTTP/1.1\r\n" |
| 16239 | "Host: www.example.org\r\n" |
| 16240 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16241 | }; |
| 16242 | MockRead ssl_reads[] = { |
| 16243 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16244 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16245 | MockRead("hello world"), |
| 16246 | MockRead(SYNCHRONOUS, OK), |
| 16247 | }; |
| 16248 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 16249 | ssl_writes, arraysize(ssl_writes)); |
| 16250 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16251 | |
| 16252 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16253 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16254 | |
| 16255 | // Set up HTTP request. |
| 16256 | |
| 16257 | HttpRequestInfo http_request; |
| 16258 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16259 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16260 | |
| 16261 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16262 | MockWrite( |
| 16263 | "GET / HTTP/1.1\r\n" |
| 16264 | "Host: www.example.org\r\n" |
| 16265 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16266 | }; |
| 16267 | MockRead http_reads[] = { |
| 16268 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16269 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16270 | MockRead("falafel"), |
| 16271 | MockRead(SYNCHRONOUS, OK), |
| 16272 | }; |
| 16273 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16274 | http_writes, arraysize(http_writes)); |
| 16275 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16276 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16277 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16278 | |
| 16279 | // Start the SSL request. |
| 16280 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16281 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16282 | ASSERT_EQ(ERR_IO_PENDING, |
| 16283 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 16284 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16285 | |
| 16286 | // Start the HTTP request. Pool should stall. |
| 16287 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16288 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16289 | ASSERT_EQ(ERR_IO_PENDING, |
| 16290 | http_trans.Start(&http_request, http_callback.callback(), |
| 16291 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16292 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16293 | |
| 16294 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16295 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16296 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16297 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16298 | EXPECT_EQ("hello world", response_data); |
| 16299 | |
| 16300 | // The SSL socket should automatically be closed, so the HTTP request can |
| 16301 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16302 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 16303 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16304 | |
| 16305 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16306 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16307 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16308 | EXPECT_EQ("falafel", response_data); |
| 16309 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16310 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16311 | } |
| 16312 | |
| 16313 | // Tests that when a SSL connection is established but there's no corresponding |
| 16314 | // request that needs it, the new socket is closed if the transport socket pool |
| 16315 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16316 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16317 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16318 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16319 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16320 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16321 | |
| 16322 | // Set up an ssl request. |
| 16323 | |
| 16324 | HttpRequestInfo ssl_request; |
| 16325 | ssl_request.method = "GET"; |
| 16326 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 16327 | |
| 16328 | // No data will be sent on the SSL socket. |
| 16329 | StaticSocketDataProvider ssl_data; |
| 16330 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16331 | |
| 16332 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16333 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16334 | |
| 16335 | // Set up HTTP request. |
| 16336 | |
| 16337 | HttpRequestInfo http_request; |
| 16338 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16339 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16340 | |
| 16341 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16342 | MockWrite( |
| 16343 | "GET / HTTP/1.1\r\n" |
| 16344 | "Host: www.example.org\r\n" |
| 16345 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16346 | }; |
| 16347 | MockRead http_reads[] = { |
| 16348 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16349 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16350 | MockRead("falafel"), |
| 16351 | MockRead(SYNCHRONOUS, OK), |
| 16352 | }; |
| 16353 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16354 | http_writes, arraysize(http_writes)); |
| 16355 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16356 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16357 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16358 | |
| 16359 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 16360 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16361 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16362 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16363 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16364 | |
| 16365 | // Start the HTTP request. Pool should stall. |
| 16366 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16367 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16368 | ASSERT_EQ(ERR_IO_PENDING, |
| 16369 | http_trans.Start(&http_request, http_callback.callback(), |
| 16370 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16371 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16372 | |
| 16373 | // The SSL connection will automatically be closed once the connection is |
| 16374 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16375 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16376 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16377 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16378 | EXPECT_EQ("falafel", response_data); |
| 16379 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16380 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16381 | } |
| 16382 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16383 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16384 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16385 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16386 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16387 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16388 | |
| 16389 | HttpRequestInfo request; |
| 16390 | request.method = "POST"; |
| 16391 | request.url = GURL("http://www.foo.com/"); |
| 16392 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16393 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16394 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16395 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16396 | // Send headers successfully, but get an error while sending the body. |
| 16397 | MockWrite data_writes[] = { |
| 16398 | MockWrite("POST / HTTP/1.1\r\n" |
| 16399 | "Host: www.foo.com\r\n" |
| 16400 | "Connection: keep-alive\r\n" |
| 16401 | "Content-Length: 3\r\n\r\n"), |
| 16402 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16403 | }; |
| 16404 | |
| 16405 | MockRead data_reads[] = { |
| 16406 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16407 | MockRead("hello world"), |
| 16408 | MockRead(SYNCHRONOUS, OK), |
| 16409 | }; |
| 16410 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16411 | arraysize(data_writes)); |
| 16412 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16413 | |
| 16414 | TestCompletionCallback callback; |
| 16415 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16416 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16417 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16418 | |
| 16419 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16420 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16421 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16422 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16423 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16424 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16425 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16426 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16427 | |
| 16428 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16429 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16430 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16431 | EXPECT_EQ("hello world", response_data); |
| 16432 | } |
| 16433 | |
| 16434 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16435 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16436 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16437 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16438 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16439 | MockWrite data_writes[] = { |
| 16440 | MockWrite("GET / HTTP/1.1\r\n" |
| 16441 | "Host: www.foo.com\r\n" |
| 16442 | "Connection: keep-alive\r\n\r\n"), |
| 16443 | MockWrite("POST / HTTP/1.1\r\n" |
| 16444 | "Host: www.foo.com\r\n" |
| 16445 | "Connection: keep-alive\r\n" |
| 16446 | "Content-Length: 3\r\n\r\n"), |
| 16447 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16448 | }; |
| 16449 | |
| 16450 | MockRead data_reads[] = { |
| 16451 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16452 | "Content-Length: 14\r\n\r\n"), |
| 16453 | MockRead("first response"), |
| 16454 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16455 | "Content-Length: 15\r\n\r\n"), |
| 16456 | MockRead("second response"), |
| 16457 | MockRead(SYNCHRONOUS, OK), |
| 16458 | }; |
| 16459 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16460 | arraysize(data_writes)); |
| 16461 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16462 | |
| 16463 | TestCompletionCallback callback; |
| 16464 | HttpRequestInfo request1; |
| 16465 | request1.method = "GET"; |
| 16466 | request1.url = GURL("http://www.foo.com/"); |
| 16467 | request1.load_flags = 0; |
| 16468 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16469 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16470 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16471 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16472 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16473 | |
| 16474 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16475 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16476 | |
| 16477 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16478 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16479 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16480 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16481 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16482 | |
| 16483 | std::string response_data1; |
| 16484 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16485 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16486 | EXPECT_EQ("first response", response_data1); |
| 16487 | // Delete the transaction to release the socket back into the socket pool. |
| 16488 | trans1.reset(); |
| 16489 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16490 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16491 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16492 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16493 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16494 | |
| 16495 | HttpRequestInfo request2; |
| 16496 | request2.method = "POST"; |
| 16497 | request2.url = GURL("http://www.foo.com/"); |
| 16498 | request2.upload_data_stream = &upload_data_stream; |
| 16499 | request2.load_flags = 0; |
| 16500 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16501 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16502 | rv = trans2.Start(&request2, 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 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16508 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16509 | ASSERT_TRUE(response2); |
[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(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16512 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16513 | |
| 16514 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16515 | rv = ReadTransaction(&trans2, &response_data2); |
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("second response", response_data2); |
| 16518 | } |
| 16519 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16520 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16521 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16522 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16523 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16524 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16525 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16526 | |
| 16527 | HttpRequestInfo request; |
| 16528 | request.method = "POST"; |
| 16529 | request.url = GURL("http://www.foo.com/"); |
| 16530 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16531 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16532 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16533 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16534 | // Send headers successfully, but get an error while sending the body. |
| 16535 | MockWrite data_writes[] = { |
| 16536 | MockWrite("POST / HTTP/1.1\r\n" |
| 16537 | "Host: www.foo.com\r\n" |
| 16538 | "Connection: keep-alive\r\n" |
| 16539 | "Content-Length: 3\r\n\r\n" |
| 16540 | "fo"), |
| 16541 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16542 | }; |
| 16543 | |
| 16544 | MockRead data_reads[] = { |
| 16545 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16546 | MockRead("hello world"), |
| 16547 | MockRead(SYNCHRONOUS, OK), |
| 16548 | }; |
| 16549 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16550 | arraysize(data_writes)); |
| 16551 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16552 | |
| 16553 | TestCompletionCallback callback; |
| 16554 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16555 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16556 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16557 | |
| 16558 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16559 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16560 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16561 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16562 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16563 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16564 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16565 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16566 | |
| 16567 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16568 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16569 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16570 | EXPECT_EQ("hello world", response_data); |
| 16571 | } |
| 16572 | |
| 16573 | // This tests the more common case than the previous test, where headers and |
| 16574 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16575 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16576 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16577 | |
| 16578 | HttpRequestInfo request; |
| 16579 | request.method = "POST"; |
| 16580 | request.url = GURL("http://www.foo.com/"); |
| 16581 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16582 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16583 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16584 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16585 | // Send headers successfully, but get an error while sending the body. |
| 16586 | MockWrite data_writes[] = { |
| 16587 | MockWrite("POST / HTTP/1.1\r\n" |
| 16588 | "Host: www.foo.com\r\n" |
| 16589 | "Connection: keep-alive\r\n" |
| 16590 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16591 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16592 | }; |
| 16593 | |
| 16594 | MockRead data_reads[] = { |
| 16595 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16596 | MockRead("hello world"), |
| 16597 | MockRead(SYNCHRONOUS, OK), |
| 16598 | }; |
| 16599 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16600 | arraysize(data_writes)); |
| 16601 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16602 | |
| 16603 | TestCompletionCallback callback; |
| 16604 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16605 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16606 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16607 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16608 | // they can't be merged with the body in a single send. Not currently |
| 16609 | // necessary since a chunked body is never merged with headers, but this makes |
| 16610 | // the test more future proof. |
| 16611 | base::RunLoop().RunUntilIdle(); |
| 16612 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16613 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16614 | |
| 16615 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16616 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16617 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16618 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16619 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16620 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16621 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16622 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16623 | |
| 16624 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16625 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16626 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16627 | EXPECT_EQ("hello world", response_data); |
| 16628 | } |
| 16629 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16630 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16631 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16632 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16633 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16634 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16635 | |
| 16636 | HttpRequestInfo request; |
| 16637 | request.method = "POST"; |
| 16638 | request.url = GURL("http://www.foo.com/"); |
| 16639 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16640 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16641 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16642 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16643 | |
| 16644 | MockWrite data_writes[] = { |
| 16645 | MockWrite("POST / HTTP/1.1\r\n" |
| 16646 | "Host: www.foo.com\r\n" |
| 16647 | "Connection: keep-alive\r\n" |
| 16648 | "Content-Length: 3\r\n\r\n"), |
| 16649 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16650 | }; |
| 16651 | |
| 16652 | MockRead data_reads[] = { |
| 16653 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16654 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16655 | MockRead("hello world"), |
| 16656 | MockRead(SYNCHRONOUS, OK), |
| 16657 | }; |
| 16658 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16659 | arraysize(data_writes)); |
| 16660 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16661 | |
| 16662 | TestCompletionCallback callback; |
| 16663 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16664 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16666 | |
| 16667 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16668 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16669 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16670 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16671 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16672 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16673 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16674 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16675 | |
| 16676 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16677 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16678 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16679 | EXPECT_EQ("hello world", response_data); |
| 16680 | } |
| 16681 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16682 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16683 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16684 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16685 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16686 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16687 | |
| 16688 | HttpRequestInfo request; |
| 16689 | request.method = "POST"; |
| 16690 | request.url = GURL("http://www.foo.com/"); |
| 16691 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16692 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16693 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16694 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16695 | // Send headers successfully, but get an error while sending the body. |
| 16696 | MockWrite data_writes[] = { |
| 16697 | MockWrite("POST / HTTP/1.1\r\n" |
| 16698 | "Host: www.foo.com\r\n" |
| 16699 | "Connection: keep-alive\r\n" |
| 16700 | "Content-Length: 3\r\n\r\n"), |
| 16701 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16702 | }; |
| 16703 | |
| 16704 | MockRead data_reads[] = { |
| 16705 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 16706 | MockRead("hello world"), |
| 16707 | MockRead(SYNCHRONOUS, OK), |
| 16708 | }; |
| 16709 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16710 | arraysize(data_writes)); |
| 16711 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16712 | |
| 16713 | TestCompletionCallback callback; |
| 16714 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16715 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16716 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16717 | |
| 16718 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16719 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16720 | } |
| 16721 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16722 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16723 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16724 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16725 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16726 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16727 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16728 | |
| 16729 | HttpRequestInfo request; |
| 16730 | request.method = "POST"; |
| 16731 | request.url = GURL("http://www.foo.com/"); |
| 16732 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16733 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16734 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16735 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16736 | // Send headers successfully, but get an error while sending the body. |
| 16737 | MockWrite data_writes[] = { |
| 16738 | MockWrite("POST / HTTP/1.1\r\n" |
| 16739 | "Host: www.foo.com\r\n" |
| 16740 | "Connection: keep-alive\r\n" |
| 16741 | "Content-Length: 3\r\n\r\n"), |
| 16742 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16743 | }; |
| 16744 | |
| 16745 | MockRead data_reads[] = { |
| 16746 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16747 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16748 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16749 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16750 | MockRead(SYNCHRONOUS, OK), |
| 16751 | }; |
| 16752 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16753 | arraysize(data_writes)); |
| 16754 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16755 | |
| 16756 | TestCompletionCallback callback; |
| 16757 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16758 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16759 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16760 | |
| 16761 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16762 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16763 | } |
| 16764 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16765 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16766 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16767 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16768 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16769 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16770 | |
| 16771 | HttpRequestInfo request; |
| 16772 | request.method = "POST"; |
| 16773 | request.url = GURL("http://www.foo.com/"); |
| 16774 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16775 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16778 | // Send headers successfully, but get an error while sending the body. |
| 16779 | MockWrite data_writes[] = { |
| 16780 | MockWrite("POST / HTTP/1.1\r\n" |
| 16781 | "Host: www.foo.com\r\n" |
| 16782 | "Connection: keep-alive\r\n" |
| 16783 | "Content-Length: 3\r\n\r\n"), |
| 16784 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16785 | }; |
| 16786 | |
| 16787 | MockRead data_reads[] = { |
| 16788 | MockRead("HTTP 0.9 rocks!"), |
| 16789 | MockRead(SYNCHRONOUS, OK), |
| 16790 | }; |
| 16791 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16792 | arraysize(data_writes)); |
| 16793 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16794 | |
| 16795 | TestCompletionCallback callback; |
| 16796 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16797 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16799 | |
| 16800 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16801 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16802 | } |
| 16803 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16804 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16805 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16806 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16807 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16808 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16809 | |
| 16810 | HttpRequestInfo request; |
| 16811 | request.method = "POST"; |
| 16812 | request.url = GURL("http://www.foo.com/"); |
| 16813 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16814 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16815 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16816 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16817 | // Send headers successfully, but get an error while sending the body. |
| 16818 | MockWrite data_writes[] = { |
| 16819 | MockWrite("POST / HTTP/1.1\r\n" |
| 16820 | "Host: www.foo.com\r\n" |
| 16821 | "Connection: keep-alive\r\n" |
| 16822 | "Content-Length: 3\r\n\r\n"), |
| 16823 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16824 | }; |
| 16825 | |
| 16826 | MockRead data_reads[] = { |
| 16827 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16828 | MockRead(SYNCHRONOUS, OK), |
| 16829 | }; |
| 16830 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16831 | arraysize(data_writes)); |
| 16832 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16833 | |
| 16834 | TestCompletionCallback callback; |
| 16835 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16836 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16837 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16838 | |
| 16839 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16840 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16841 | } |
| 16842 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16843 | // Verify that proxy headers are not sent to the destination server when |
| 16844 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16845 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16846 | HttpRequestInfo request; |
| 16847 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16848 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16849 | AddWebSocketHeaders(&request.extra_headers); |
| 16850 | |
| 16851 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16852 | session_deps_.proxy_service = |
| 16853 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16854 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16855 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16856 | |
| 16857 | // Since a proxy is configured, try to establish a tunnel. |
| 16858 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16859 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16860 | "Host: www.example.org:443\r\n" |
| 16861 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16862 | |
| 16863 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16864 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16865 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16866 | "Host: www.example.org:443\r\n" |
| 16867 | "Proxy-Connection: keep-alive\r\n" |
| 16868 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16869 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16870 | MockWrite("GET / HTTP/1.1\r\n" |
| 16871 | "Host: www.example.org\r\n" |
| 16872 | "Connection: Upgrade\r\n" |
| 16873 | "Upgrade: websocket\r\n" |
| 16874 | "Origin: http://www.example.org\r\n" |
| 16875 | "Sec-WebSocket-Version: 13\r\n" |
| 16876 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16877 | }; |
| 16878 | |
| 16879 | // The proxy responds to the connect with a 407, using a persistent |
| 16880 | // connection. |
| 16881 | MockRead data_reads[] = { |
| 16882 | // No credentials. |
| 16883 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16884 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16885 | MockRead("Content-Length: 0\r\n"), |
| 16886 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16887 | |
| 16888 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16889 | |
| 16890 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16891 | MockRead("Upgrade: websocket\r\n"), |
| 16892 | MockRead("Connection: Upgrade\r\n"), |
| 16893 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16894 | }; |
| 16895 | |
| 16896 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16897 | arraysize(data_writes)); |
| 16898 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16899 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16901 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16902 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16903 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16904 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16905 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16906 | &websocket_stream_create_helper); |
| 16907 | |
| 16908 | { |
| 16909 | TestCompletionCallback callback; |
| 16910 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16911 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16913 | |
| 16914 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16915 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16916 | } |
| 16917 | |
| 16918 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16919 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16920 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16921 | EXPECT_EQ(407, response->headers->response_code()); |
| 16922 | |
| 16923 | { |
| 16924 | TestCompletionCallback callback; |
| 16925 | |
| 16926 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16927 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16928 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16929 | |
| 16930 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16931 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16932 | } |
| 16933 | |
| 16934 | response = trans->GetResponseInfo(); |
| 16935 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16936 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16937 | |
| 16938 | EXPECT_EQ(101, response->headers->response_code()); |
| 16939 | |
| 16940 | trans.reset(); |
| 16941 | session->CloseAllConnections(); |
| 16942 | } |
| 16943 | |
| 16944 | // Verify that proxy headers are not sent to the destination server when |
| 16945 | // establishing a tunnel for an insecure WebSocket connection. |
| 16946 | // This requires the authentication info to be injected into the auth cache |
| 16947 | // due to crbug.com/395064 |
| 16948 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16949 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16950 | HttpRequestInfo request; |
| 16951 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16952 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16953 | AddWebSocketHeaders(&request.extra_headers); |
| 16954 | |
| 16955 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16956 | session_deps_.proxy_service = |
| 16957 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16958 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16959 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16960 | |
| 16961 | MockWrite data_writes[] = { |
| 16962 | // Try to establish a tunnel for the WebSocket connection, with |
| 16963 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16964 | // they cannot and will not use the same TCP/IP connection as the |
| 16965 | // preflight HTTP request. |
| 16966 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16967 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16968 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16969 | "Proxy-Connection: keep-alive\r\n" |
| 16970 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16971 | |
| 16972 | MockWrite( |
| 16973 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16974 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16975 | "Connection: Upgrade\r\n" |
| 16976 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16977 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16978 | "Sec-WebSocket-Version: 13\r\n" |
| 16979 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16980 | }; |
| 16981 | |
| 16982 | MockRead data_reads[] = { |
| 16983 | // HTTP CONNECT with credentials. |
| 16984 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16985 | |
| 16986 | // WebSocket connection established inside tunnel. |
| 16987 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16988 | MockRead("Upgrade: websocket\r\n"), |
| 16989 | MockRead("Connection: Upgrade\r\n"), |
| 16990 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16991 | }; |
| 16992 | |
| 16993 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16994 | arraysize(data_writes)); |
| 16995 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16996 | |
| 16997 | session->http_auth_cache()->Add( |
| 16998 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16999 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17000 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17001 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17002 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17003 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 17004 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17005 | &websocket_stream_create_helper); |
| 17006 | |
| 17007 | TestCompletionCallback callback; |
| 17008 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17009 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17010 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17011 | |
| 17012 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17013 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17014 | |
| 17015 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17016 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17017 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17018 | |
| 17019 | EXPECT_EQ(101, response->headers->response_code()); |
| 17020 | |
| 17021 | trans.reset(); |
| 17022 | session->CloseAllConnections(); |
| 17023 | } |
| 17024 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17025 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17026 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17027 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17028 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17029 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17030 | |
| 17031 | HttpRequestInfo request; |
| 17032 | request.method = "POST"; |
| 17033 | request.url = GURL("http://www.foo.com/"); |
| 17034 | request.upload_data_stream = &upload_data_stream; |
| 17035 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17036 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17037 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17038 | MockWrite data_writes[] = { |
| 17039 | MockWrite("POST / HTTP/1.1\r\n" |
| 17040 | "Host: www.foo.com\r\n" |
| 17041 | "Connection: keep-alive\r\n" |
| 17042 | "Content-Length: 3\r\n\r\n"), |
| 17043 | MockWrite("foo"), |
| 17044 | }; |
| 17045 | |
| 17046 | MockRead data_reads[] = { |
| 17047 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17048 | MockRead(SYNCHRONOUS, OK), |
| 17049 | }; |
| 17050 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17051 | arraysize(data_writes)); |
| 17052 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17053 | |
| 17054 | TestCompletionCallback callback; |
| 17055 | |
| 17056 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17057 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17058 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17059 | |
| 17060 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17061 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17062 | |
| 17063 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17064 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17065 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17066 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17067 | } |
| 17068 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17069 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17070 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17071 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17072 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17073 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17074 | |
| 17075 | HttpRequestInfo request; |
| 17076 | request.method = "POST"; |
| 17077 | request.url = GURL("http://www.foo.com/"); |
| 17078 | request.upload_data_stream = &upload_data_stream; |
| 17079 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17080 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17081 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17082 | MockWrite data_writes[] = { |
| 17083 | MockWrite("POST / HTTP/1.1\r\n" |
| 17084 | "Host: www.foo.com\r\n" |
| 17085 | "Connection: keep-alive\r\n" |
| 17086 | "Content-Length: 3\r\n\r\n"), |
| 17087 | MockWrite("foo"), |
| 17088 | }; |
| 17089 | |
| 17090 | MockRead data_reads[] = { |
| 17091 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17092 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17093 | MockRead(SYNCHRONOUS, OK), |
| 17094 | }; |
| 17095 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17096 | arraysize(data_writes)); |
| 17097 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17098 | |
| 17099 | TestCompletionCallback callback; |
| 17100 | |
| 17101 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17102 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17103 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17104 | |
| 17105 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17106 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17107 | |
| 17108 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17109 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17110 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17111 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17112 | } |
| 17113 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17114 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17115 | ChunkedUploadDataStream upload_data_stream(0); |
| 17116 | |
| 17117 | HttpRequestInfo request; |
| 17118 | request.method = "POST"; |
| 17119 | request.url = GURL("http://www.foo.com/"); |
| 17120 | request.upload_data_stream = &upload_data_stream; |
| 17121 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17122 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17123 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17124 | // Send headers successfully, but get an error while sending the body. |
| 17125 | MockWrite data_writes[] = { |
| 17126 | MockWrite("POST / HTTP/1.1\r\n" |
| 17127 | "Host: www.foo.com\r\n" |
| 17128 | "Connection: keep-alive\r\n" |
| 17129 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17130 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17131 | }; |
| 17132 | |
| 17133 | MockRead data_reads[] = { |
| 17134 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17135 | MockRead(SYNCHRONOUS, OK), |
| 17136 | }; |
| 17137 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17138 | arraysize(data_writes)); |
| 17139 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17140 | |
| 17141 | TestCompletionCallback callback; |
| 17142 | |
| 17143 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17144 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17145 | |
| 17146 | base::RunLoop().RunUntilIdle(); |
| 17147 | upload_data_stream.AppendData("f", 1, false); |
| 17148 | |
| 17149 | base::RunLoop().RunUntilIdle(); |
| 17150 | upload_data_stream.AppendData("oo", 2, true); |
| 17151 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17152 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17153 | |
| 17154 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17155 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17156 | |
| 17157 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17158 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17159 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17160 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17161 | } |
| 17162 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17163 | // Confirm that transactions whose throttle is created in (and stays in) |
| 17164 | // the unthrottled state are not blocked. |
| 17165 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 17166 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17167 | std::unique_ptr<HttpNetworkSession> session( |
| 17168 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17169 | |
| 17170 | // Send a simple request and make sure it goes through. |
| 17171 | HttpRequestInfo request; |
| 17172 | request.method = "GET"; |
| 17173 | request.url = GURL("http://www.example.org/"); |
| 17174 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17175 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17176 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17177 | |
| 17178 | MockWrite data_writes[] = { |
| 17179 | MockWrite("GET / HTTP/1.1\r\n" |
| 17180 | "Host: www.example.org\r\n" |
| 17181 | "Connection: keep-alive\r\n\r\n"), |
| 17182 | }; |
| 17183 | MockRead data_reads[] = { |
| 17184 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17185 | MockRead(SYNCHRONOUS, OK), |
| 17186 | }; |
| 17187 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17188 | arraysize(data_writes)); |
| 17189 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17190 | |
| 17191 | TestCompletionCallback callback; |
| 17192 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17193 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17194 | } |
| 17195 | |
| 17196 | // Confirm requests can be blocked by a throttler, and are resumed |
| 17197 | // when the throttle is unblocked. |
| 17198 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 17199 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17200 | std::unique_ptr<HttpNetworkSession> session( |
| 17201 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17202 | |
| 17203 | // Send a simple request and make sure it goes through. |
| 17204 | HttpRequestInfo request; |
| 17205 | request.method = "GET"; |
| 17206 | request.url = GURL("http://www.example.org/"); |
| 17207 | |
| 17208 | MockWrite data_writes[] = { |
| 17209 | MockWrite("GET / HTTP/1.1\r\n" |
| 17210 | "Host: www.example.org\r\n" |
| 17211 | "Connection: keep-alive\r\n\r\n"), |
| 17212 | }; |
| 17213 | MockRead data_reads[] = { |
| 17214 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17215 | MockRead(SYNCHRONOUS, OK), |
| 17216 | }; |
| 17217 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17218 | arraysize(data_writes)); |
| 17219 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17220 | |
| 17221 | // Start a request that will be throttled at start; confirm it |
| 17222 | // doesn't complete. |
| 17223 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17224 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17225 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17226 | |
| 17227 | TestCompletionCallback callback; |
| 17228 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17229 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17230 | |
| 17231 | base::RunLoop().RunUntilIdle(); |
| 17232 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17233 | EXPECT_FALSE(callback.have_result()); |
| 17234 | |
| 17235 | // Confirm the request goes on to complete when unthrottled. |
| 17236 | throttler->UnthrottleAllRequests(); |
| 17237 | base::RunLoop().RunUntilIdle(); |
| 17238 | ASSERT_TRUE(callback.have_result()); |
| 17239 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17240 | } |
| 17241 | |
| 17242 | // Destroy a request while it's throttled. |
| 17243 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 17244 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17245 | std::unique_ptr<HttpNetworkSession> session( |
| 17246 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17247 | |
| 17248 | // Send a simple request and make sure it goes through. |
| 17249 | HttpRequestInfo request; |
| 17250 | request.method = "GET"; |
| 17251 | request.url = GURL("http://www.example.org/"); |
| 17252 | |
| 17253 | MockWrite data_writes[] = { |
| 17254 | MockWrite("GET / HTTP/1.1\r\n" |
| 17255 | "Host: www.example.org\r\n" |
| 17256 | "Connection: keep-alive\r\n\r\n"), |
| 17257 | }; |
| 17258 | MockRead data_reads[] = { |
| 17259 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17260 | MockRead(SYNCHRONOUS, OK), |
| 17261 | }; |
| 17262 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17263 | arraysize(data_writes)); |
| 17264 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17265 | |
| 17266 | // Start a request that will be throttled at start; confirm it |
| 17267 | // doesn't complete. |
| 17268 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17269 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17270 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17271 | |
| 17272 | TestCompletionCallback callback; |
| 17273 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17274 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17275 | |
| 17276 | base::RunLoop().RunUntilIdle(); |
| 17277 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17278 | EXPECT_FALSE(callback.have_result()); |
| 17279 | |
| 17280 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 17281 | trans.reset(); |
| 17282 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 17283 | } |
| 17284 | |
| 17285 | // Confirm the throttler receives SetPriority calls. |
| 17286 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 17287 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17288 | std::unique_ptr<HttpNetworkSession> session( |
| 17289 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17290 | |
| 17291 | // Send a simple request and make sure it goes through. |
| 17292 | HttpRequestInfo request; |
| 17293 | request.method = "GET"; |
| 17294 | request.url = GURL("http://www.example.org/"); |
| 17295 | |
| 17296 | MockWrite data_writes[] = { |
| 17297 | MockWrite("GET / HTTP/1.1\r\n" |
| 17298 | "Host: www.example.org\r\n" |
| 17299 | "Connection: keep-alive\r\n\r\n"), |
| 17300 | }; |
| 17301 | MockRead data_reads[] = { |
| 17302 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17303 | MockRead(SYNCHRONOUS, OK), |
| 17304 | }; |
| 17305 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17306 | arraysize(data_writes)); |
| 17307 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17308 | |
| 17309 | throttler->set_throttle_new_requests(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17310 | auto trans = std::make_unique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17311 | // Start the transaction to associate a throttle with it. |
| 17312 | TestCompletionCallback callback; |
| 17313 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17314 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17315 | |
| 17316 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 17317 | trans->SetPriority(LOW); |
| 17318 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 17319 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 17320 | |
| 17321 | throttler->UnthrottleAllRequests(); |
| 17322 | base::RunLoop().RunUntilIdle(); |
| 17323 | ASSERT_TRUE(callback.have_result()); |
| 17324 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17325 | } |
| 17326 | |
| 17327 | // Confirm that unthrottling from a SetPriority call by the |
| 17328 | // throttler works properly. |
| 17329 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 17330 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17331 | std::unique_ptr<HttpNetworkSession> session( |
| 17332 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17333 | |
| 17334 | // Send a simple request and make sure it goes through. |
| 17335 | HttpRequestInfo request; |
| 17336 | request.method = "GET"; |
| 17337 | request.url = GURL("http://www.example.org/"); |
| 17338 | |
| 17339 | MockWrite data_writes[] = { |
| 17340 | MockWrite("GET / HTTP/1.1\r\n" |
| 17341 | "Host: www.example.org\r\n" |
| 17342 | "Connection: keep-alive\r\n\r\n"), |
| 17343 | }; |
| 17344 | MockRead data_reads[] = { |
| 17345 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17346 | MockRead(SYNCHRONOUS, OK), |
| 17347 | }; |
| 17348 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17349 | arraysize(data_writes)); |
| 17350 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17351 | |
| 17352 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17353 | data_writes, arraysize(data_writes)); |
| 17354 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17355 | |
| 17356 | // Start a request that will be throttled at start; confirm it |
| 17357 | // doesn't complete. |
| 17358 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17359 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17360 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17361 | |
| 17362 | TestCompletionCallback callback; |
| 17363 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17364 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17365 | |
| 17366 | base::RunLoop().RunUntilIdle(); |
| 17367 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17368 | EXPECT_FALSE(callback.have_result()); |
| 17369 | |
| 17370 | // Create a new request, call SetPriority on it to unthrottle, |
| 17371 | // and make sure that allows the original request to complete. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17372 | auto trans1 = std::make_unique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17373 | throttler->set_priority_change_closure( |
| 17374 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 17375 | base::Unretained(throttler))); |
| 17376 | |
| 17377 | // Start the transaction to associate a throttle with it. |
| 17378 | TestCompletionCallback callback1; |
| 17379 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 17380 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17381 | |
| 17382 | trans1->SetPriority(IDLE); |
| 17383 | |
| 17384 | base::RunLoop().RunUntilIdle(); |
| 17385 | ASSERT_TRUE(callback.have_result()); |
| 17386 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17387 | ASSERT_TRUE(callback1.have_result()); |
| 17388 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 17389 | } |
| 17390 | |
| 17391 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17392 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17393 | |
| 17394 | // Confirm that destroying a transaction from a SetPriority call by the |
| 17395 | // throttler works properly. |
| 17396 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 17397 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17398 | std::unique_ptr<HttpNetworkSession> session( |
| 17399 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17400 | |
| 17401 | // Send a simple request and make sure it goes through. |
| 17402 | HttpRequestInfo request; |
| 17403 | request.method = "GET"; |
| 17404 | request.url = GURL("http://www.example.org/"); |
| 17405 | |
| 17406 | MockWrite data_writes[] = { |
| 17407 | MockWrite("GET / HTTP/1.1\r\n" |
| 17408 | "Host: www.example.org\r\n" |
| 17409 | "Connection: keep-alive\r\n\r\n"), |
| 17410 | }; |
| 17411 | MockRead data_reads[] = { |
| 17412 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17413 | MockRead(SYNCHRONOUS, OK), |
| 17414 | }; |
| 17415 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17416 | arraysize(data_writes)); |
| 17417 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17418 | |
| 17419 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17420 | data_writes, arraysize(data_writes)); |
| 17421 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17422 | |
| 17423 | // Start a request that will be throttled at start; confirm it |
| 17424 | // doesn't complete. |
| 17425 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17426 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17427 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17428 | |
| 17429 | TestCompletionCallback callback; |
| 17430 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17431 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17432 | |
| 17433 | base::RunLoop().RunUntilIdle(); |
| 17434 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17435 | EXPECT_FALSE(callback.have_result()); |
| 17436 | |
| 17437 | // Arrange for the set priority call on the above transaction to delete |
| 17438 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17439 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17440 | throttler->set_priority_change_closure( |
| 17441 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 17442 | |
| 17443 | // Call it and check results (partially a "doesn't crash" test). |
| 17444 | trans_ptr->SetPriority(IDLE); |
| 17445 | trans_ptr = nullptr; // No longer a valid pointer. |
| 17446 | |
| 17447 | base::RunLoop().RunUntilIdle(); |
| 17448 | ASSERT_FALSE(callback.have_result()); |
| 17449 | } |
| 17450 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17451 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17452 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17453 | const std::string https_url = "https://www.example.com"; |
| 17454 | HttpRequestInfo request; |
| 17455 | request.url = GURL(https_url); |
| 17456 | request.method = "GET"; |
| 17457 | |
| 17458 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17459 | ssl.ssl_info.token_binding_negotiated = true; |
| 17460 | ssl.ssl_info.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17461 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17463 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17464 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17465 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 17466 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17467 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 17468 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 17469 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17470 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17471 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17472 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17473 | |
| 17474 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17475 | TestCompletionCallback callback; |
| 17476 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17477 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17478 | |
| 17479 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17480 | |
| 17481 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17482 | HttpRequestHeaders headers; |
| 17483 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17484 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17485 | } |
| 17486 | #endif // !defined(OS_IOS) |
| 17487 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17488 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17489 | const std::string& accept_encoding, |
| 17490 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17491 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17492 | bool should_match) { |
| 17493 | HttpRequestInfo request; |
| 17494 | request.method = "GET"; |
| 17495 | request.url = GURL("http://www.foo.com/"); |
| 17496 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17497 | accept_encoding); |
| 17498 | |
| 17499 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17500 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17501 | // Send headers successfully, but get an error while sending the body. |
| 17502 | MockWrite data_writes[] = { |
| 17503 | MockWrite("GET / HTTP/1.1\r\n" |
| 17504 | "Host: www.foo.com\r\n" |
| 17505 | "Connection: keep-alive\r\n" |
| 17506 | "Accept-Encoding: "), |
| 17507 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17508 | }; |
| 17509 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17510 | std::string response_code = "200 OK"; |
| 17511 | std::string extra; |
| 17512 | if (!location.empty()) { |
| 17513 | response_code = "301 Redirect\r\nLocation: "; |
| 17514 | response_code.append(location); |
| 17515 | } |
| 17516 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17517 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17518 | MockRead("HTTP/1.0 "), |
| 17519 | MockRead(response_code.data()), |
| 17520 | MockRead("\r\nContent-Encoding: "), |
| 17521 | MockRead(content_encoding.data()), |
| 17522 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17523 | MockRead(SYNCHRONOUS, OK), |
| 17524 | }; |
| 17525 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17526 | arraysize(data_writes)); |
| 17527 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17528 | |
| 17529 | TestCompletionCallback callback; |
| 17530 | |
| 17531 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17532 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17533 | |
| 17534 | rv = callback.WaitForResult(); |
| 17535 | if (should_match) { |
| 17536 | EXPECT_THAT(rv, IsOk()); |
| 17537 | } else { |
| 17538 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17539 | } |
| 17540 | } |
| 17541 | |
| 17542 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17543 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17544 | } |
| 17545 | |
| 17546 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17547 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17548 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17549 | } |
| 17550 | |
| 17551 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17552 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17553 | "", false); |
| 17554 | } |
| 17555 | |
| 17556 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17557 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17558 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17559 | } |
| 17560 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17561 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17562 | ProxyConfig proxy_config; |
| 17563 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17564 | proxy_config.set_pac_mandatory(true); |
| 17565 | MockAsyncProxyResolver resolver; |
| 17566 | session_deps_.proxy_service.reset(new ProxyService( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17567 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 17568 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17569 | |
| 17570 | HttpRequestInfo request; |
| 17571 | request.method = "GET"; |
| 17572 | request.url = GURL("http://www.example.org/"); |
| 17573 | |
| 17574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17575 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17576 | |
| 17577 | TestCompletionCallback callback; |
| 17578 | |
| 17579 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17580 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17581 | EXPECT_THAT(callback.WaitForResult(), |
| 17582 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17583 | } |
| 17584 | |
| 17585 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17586 | ProxyConfig proxy_config; |
| 17587 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17588 | proxy_config.set_pac_mandatory(true); |
| 17589 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17590 | new MockAsyncProxyResolverFactory(false); |
| 17591 | MockAsyncProxyResolver resolver; |
| 17592 | session_deps_.proxy_service.reset( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17593 | new ProxyService(std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17594 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 17595 | HttpRequestInfo request; |
| 17596 | request.method = "GET"; |
| 17597 | request.url = GURL("http://www.example.org/"); |
| 17598 | |
| 17599 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17600 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17601 | |
| 17602 | TestCompletionCallback callback; |
| 17603 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17604 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17605 | |
| 17606 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17607 | ERR_FAILED, &resolver); |
| 17608 | EXPECT_THAT(callback.WaitForResult(), |
| 17609 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17610 | } |
| 17611 | |
| 17612 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
| 17613 | session_deps_.proxy_service = |
| 17614 | ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
| 17615 | session_deps_.enable_quic = false; |
| 17616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17617 | |
| 17618 | HttpRequestInfo request; |
| 17619 | request.method = "GET"; |
| 17620 | request.url = GURL("http://www.example.org/"); |
| 17621 | |
| 17622 | TestCompletionCallback callback; |
| 17623 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17624 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17625 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17626 | |
| 17627 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17628 | } |
| 17629 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17630 | } // namespace net |