[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" |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 26 | #include "base/strings/string_piece.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 27 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 28 | #include "base/strings/utf_string_conversions.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 29 | #include "base/test/scoped_task_environment.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 30 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 31 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 32 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 33 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 34 | #include "net/base/completion_callback.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 35 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 36 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 37 | #include "net/base/load_timing_info.h" |
| 38 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 39 | #include "net/base/net_errors.h" |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 40 | #include "net/base/network_throttle_manager.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 41 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 42 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 43 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 44 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 45 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 46 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 47 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 48 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 49 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 50 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 51 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 52 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 53 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 54 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 55 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 56 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 57 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 58 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 59 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 60 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 61 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 62 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 63 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 64 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 65 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 66 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 67 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 68 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 69 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 70 | #include "net/log/test_net_log_entry.h" |
| 71 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 72 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 73 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 74 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 75 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 76 | #include "net/proxy_resolution/proxy_resolver.h" |
| 77 | #include "net/proxy_resolution/proxy_resolver_factory.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" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 103 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 104 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 105 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 106 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 107 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 108 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 109 | #if defined(NTLM_PORTABLE) |
| 110 | #include "base/base64.h" |
| 111 | #include "net/ntlm/ntlm_test_data.h" |
| 112 | #endif |
| 113 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 114 | using net::test::IsError; |
| 115 | using net::test::IsOk; |
| 116 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 117 | using base::ASCIIToUTF16; |
| 118 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 119 | //----------------------------------------------------------------------------- |
| 120 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 121 | namespace net { |
| 122 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 123 | namespace { |
| 124 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 125 | class TestNetworkStreamThrottler : public NetworkThrottleManager { |
| 126 | public: |
| 127 | TestNetworkStreamThrottler() |
| 128 | : throttle_new_requests_(false), |
| 129 | num_set_priority_calls_(0), |
| 130 | last_priority_set_(IDLE) {} |
| 131 | |
| 132 | ~TestNetworkStreamThrottler() override { |
| 133 | EXPECT_TRUE(outstanding_throttles_.empty()); |
| 134 | } |
| 135 | |
| 136 | // NetworkThrottleManager |
| 137 | std::unique_ptr<Throttle> CreateThrottle(ThrottleDelegate* delegate, |
| 138 | RequestPriority priority, |
| 139 | bool ignore_limits) override { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 140 | auto test_throttle = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 141 | std::make_unique<TestThrottle>(throttle_new_requests_, delegate, this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 142 | outstanding_throttles_.insert(test_throttle.get()); |
| 143 | return std::move(test_throttle); |
| 144 | } |
| 145 | |
| 146 | void UnthrottleAllRequests() { |
| 147 | std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
vmpstr | 6d9996c8 | 2017-02-23 00:43:25 | [diff] [blame] | 148 | for (auto* throttle : outstanding_throttles_copy) { |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 149 | if (throttle->IsBlocked()) |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 150 | throttle->Unthrottle(); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | void set_throttle_new_requests(bool throttle_new_requests) { |
| 155 | throttle_new_requests_ = throttle_new_requests; |
| 156 | } |
| 157 | |
| 158 | // Includes both throttled and unthrottled throttles. |
| 159 | size_t num_outstanding_requests() const { |
| 160 | return outstanding_throttles_.size(); |
| 161 | } |
| 162 | |
| 163 | int num_set_priority_calls() const { return num_set_priority_calls_; } |
| 164 | RequestPriority last_priority_set() const { return last_priority_set_; } |
| 165 | void set_priority_change_closure( |
| 166 | const base::Closure& priority_change_closure) { |
| 167 | priority_change_closure_ = priority_change_closure; |
| 168 | } |
| 169 | |
| 170 | private: |
| 171 | class TestThrottle : public NetworkThrottleManager::Throttle { |
| 172 | public: |
| 173 | ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
| 174 | |
| 175 | // Throttle |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 176 | bool IsBlocked() const override { return throttled_; } |
| 177 | RequestPriority Priority() const override { |
| 178 | NOTREACHED(); |
| 179 | return IDLE; |
| 180 | } |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 181 | void SetPriority(RequestPriority priority) override { |
| 182 | throttler_->SetPriorityCalled(priority); |
| 183 | } |
| 184 | |
| 185 | TestThrottle(bool throttled, |
| 186 | ThrottleDelegate* delegate, |
| 187 | TestNetworkStreamThrottler* throttler) |
| 188 | : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 189 | |
| 190 | void Unthrottle() { |
| 191 | EXPECT_TRUE(throttled_); |
| 192 | |
| 193 | throttled_ = false; |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 194 | delegate_->OnThrottleUnblocked(this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | bool throttled_; |
| 198 | ThrottleDelegate* delegate_; |
| 199 | TestNetworkStreamThrottler* throttler_; |
| 200 | }; |
| 201 | |
| 202 | void OnThrottleDestroyed(TestThrottle* throttle) { |
| 203 | EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 204 | outstanding_throttles_.erase(throttle); |
| 205 | } |
| 206 | |
| 207 | void SetPriorityCalled(RequestPriority priority) { |
| 208 | ++num_set_priority_calls_; |
| 209 | last_priority_set_ = priority; |
| 210 | if (!priority_change_closure_.is_null()) |
| 211 | priority_change_closure_.Run(); |
| 212 | } |
| 213 | |
| 214 | // Includes both throttled and unthrottled throttles. |
| 215 | std::set<TestThrottle*> outstanding_throttles_; |
| 216 | bool throttle_new_requests_; |
| 217 | int num_set_priority_calls_; |
| 218 | RequestPriority last_priority_set_; |
| 219 | base::Closure priority_change_closure_; |
| 220 | |
| 221 | DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler); |
| 222 | }; |
| 223 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 224 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 225 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 226 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 227 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 228 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 229 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 230 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 231 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 232 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 233 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 234 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 235 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 236 | const char kAlternativeServiceHttpHeader[] = |
| 237 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 238 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 239 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 240 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 241 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 242 | } |
| 243 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 244 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 245 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 246 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 247 | } |
| 248 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 249 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 250 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 251 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 252 | } |
| 253 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 254 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 255 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 256 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 257 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 258 | if (!params) |
| 259 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 260 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 261 | if (!params->GetList("headers", &header_list)) |
| 262 | return false; |
| 263 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 264 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 265 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 266 | return true; |
| 267 | } |
| 268 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 269 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 270 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 271 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 272 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 273 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 274 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 275 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 276 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 277 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 278 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 279 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 280 | |
| 281 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 282 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 283 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 284 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 285 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 286 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 287 | } |
| 288 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 289 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 290 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 291 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 292 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 293 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 294 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 295 | |
| 296 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 297 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 298 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 299 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 300 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 301 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 302 | load_timing_info.send_start); |
| 303 | |
| 304 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 305 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 306 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 307 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 308 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 309 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 313 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 314 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 315 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 316 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 317 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 318 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 319 | |
| 320 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 321 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 322 | load_timing_info.proxy_resolve_end); |
| 323 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 324 | load_timing_info.send_start); |
| 325 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 326 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 327 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 328 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 329 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 330 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 334 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 335 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 336 | int connect_timing_flags) { |
| 337 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 338 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 339 | |
| 340 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 341 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 342 | load_timing_info.proxy_resolve_end); |
| 343 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 344 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 345 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 346 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 347 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 348 | load_timing_info.send_start); |
| 349 | |
| 350 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 351 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 352 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 353 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 354 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 355 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 356 | } |
| 357 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 358 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 359 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 360 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 361 | } |
| 362 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 363 | // Note that the pointer written into |*throttler| will only be valid |
| 364 | // for the lifetime of the returned HttpNetworkSession. |
| 365 | std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler( |
| 366 | SpdySessionDependencies* session_deps, |
| 367 | TestNetworkStreamThrottler** throttler) { |
| 368 | std::unique_ptr<HttpNetworkSession> session( |
| 369 | SpdySessionDependencies::SpdyCreateSession(session_deps)); |
| 370 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 371 | auto owned_throttler = std::make_unique<TestNetworkStreamThrottler>(); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 372 | *throttler = owned_throttler.get(); |
| 373 | |
| 374 | HttpNetworkSessionPeer peer(session.get()); |
| 375 | peer.SetNetworkStreamThrottler(std::move(owned_throttler)); |
| 376 | |
| 377 | return session; |
| 378 | } |
| 379 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 380 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 381 | public: |
| 382 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 383 | |
| 384 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 385 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 386 | std::unique_ptr<ProxyResolver>* result, |
| 387 | const CompletionCallback& callback, |
| 388 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 389 | return ERR_PAC_SCRIPT_FAILED; |
| 390 | } |
| 391 | }; |
| 392 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 393 | } // namespace |
| 394 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 395 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 396 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 397 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 398 | // Important to restore the per-pool limit first, since the pool limit must |
| 399 | // always be greater than group limit, and the tests reduce both limits. |
| 400 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 401 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 402 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 403 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 404 | } |
| 405 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 406 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 407 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 408 | : ssl_(ASYNC, OK), |
| 409 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 410 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 411 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 412 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 413 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 414 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 415 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 416 | struct SimpleGetHelperResult { |
| 417 | int rv; |
| 418 | std::string status_line; |
| 419 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 420 | int64_t total_received_bytes; |
| 421 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 422 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 423 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 424 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 425 | }; |
| 426 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 427 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 428 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 429 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 430 | } |
| 431 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 432 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 433 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 434 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 435 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 436 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 437 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 438 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 439 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 440 | } |
| 441 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 442 | // Either |write_failure| specifies a write failure or |read_failure| |
| 443 | // specifies a read failure when using a reused socket. In either case, the |
| 444 | // failure should cause the network transaction to resend the request, and the |
| 445 | // other argument should be NULL. |
| 446 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 447 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 448 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 449 | // Either |write_failure| specifies a write failure or |read_failure| |
| 450 | // specifies a read failure when using a reused socket. In either case, the |
| 451 | // failure should cause the network transaction to resend the request, and the |
| 452 | // other argument should be NULL. |
| 453 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 454 | const MockRead* read_failure, |
| 455 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 456 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 457 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 458 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 459 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 460 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 461 | HttpRequestInfo request; |
| 462 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 463 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 464 | request.traffic_annotation = |
| 465 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 466 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 467 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 468 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 469 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 470 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 471 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 472 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 473 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 474 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 476 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 477 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 478 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 479 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 481 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 482 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 483 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 484 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 485 | |
| 486 | // Even in the failure cases that use this function, connections are always |
| 487 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 488 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 489 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 490 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 491 | if (out.rv != OK) |
| 492 | return out; |
| 493 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 494 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 495 | // Can't use ASSERT_* inside helper functions like this, so |
| 496 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 497 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 498 | out.rv = ERR_UNEXPECTED; |
| 499 | return out; |
| 500 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 501 | out.status_line = response->headers->GetStatusLine(); |
| 502 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 503 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 504 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 505 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 506 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 507 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 508 | EXPECT_EQ(got_endpoint, |
| 509 | out.remote_endpoint_after_start.address().size() > 0); |
| 510 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 511 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 512 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 513 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 514 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 515 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 516 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 517 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 518 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 519 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 520 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 521 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 522 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 523 | std::string line; |
| 524 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 525 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 526 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 527 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 528 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 529 | std::string value; |
| 530 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 531 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 532 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 533 | EXPECT_EQ("keep-alive", value); |
| 534 | |
| 535 | std::string response_headers; |
| 536 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 537 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 538 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 539 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 540 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 541 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 542 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 543 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 544 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 545 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 546 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 547 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 548 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 549 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 550 | MockWrite data_writes[] = { |
| 551 | MockWrite("GET / HTTP/1.1\r\n" |
| 552 | "Host: www.example.org\r\n" |
| 553 | "Connection: keep-alive\r\n\r\n"), |
| 554 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 555 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 556 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 557 | arraysize(data_writes)); |
| 558 | StaticSocketDataProvider* data[] = {&reads}; |
| 559 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 560 | |
| 561 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 562 | out.total_sent_bytes); |
| 563 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 564 | } |
| 565 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 566 | void AddSSLSocketData() { |
| 567 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 568 | ssl_.ssl_info.cert = |
| 569 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 570 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 571 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 572 | } |
| 573 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 574 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 575 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 576 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 577 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 578 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 579 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 580 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 581 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 582 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 583 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 584 | |
| 585 | // Original socket limits. Some tests set these. Safest to always restore |
| 586 | // them once each test has been run. |
| 587 | int old_max_group_sockets_; |
| 588 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 589 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 590 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 591 | namespace { |
| 592 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 593 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 594 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 595 | BeforeHeadersSentHandler() |
| 596 | : observed_before_headers_sent_with_proxy_(false), |
| 597 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 598 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 599 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 600 | HttpRequestHeaders* request_headers) { |
| 601 | observed_before_headers_sent_ = true; |
| 602 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 603 | !proxy_info.is_quic()) { |
| 604 | return; |
| 605 | } |
| 606 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 607 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 608 | } |
| 609 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 610 | bool observed_before_headers_sent_with_proxy() const { |
| 611 | return observed_before_headers_sent_with_proxy_; |
| 612 | } |
| 613 | |
| 614 | bool observed_before_headers_sent() const { |
| 615 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | std::string observed_proxy_server_uri() const { |
| 619 | return observed_proxy_server_uri_; |
| 620 | } |
| 621 | |
| 622 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 623 | bool observed_before_headers_sent_with_proxy_; |
| 624 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 625 | std::string observed_proxy_server_uri_; |
| 626 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 627 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 628 | }; |
| 629 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 630 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 631 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 632 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 633 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 634 | const int sizeof_row = strlen(row); |
| 635 | const int num_rows = static_cast<int>( |
| 636 | ceil(static_cast<float>(size) / sizeof_row)); |
| 637 | const int sizeof_data = num_rows * sizeof_row; |
| 638 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 639 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 640 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 641 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 642 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 643 | } |
| 644 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 645 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 646 | uint64_t MockGetMSTime() { |
| 647 | // Tue, 23 May 2017 20:13:07 +0000 |
| 648 | return 131400439870000000; |
| 649 | } |
| 650 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 651 | // Alternative functions that eliminate randomness and dependency on the local |
| 652 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 653 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 654 | // This is set to 0xaa because the client challenge for testing in |
| 655 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 656 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 657 | } |
| 658 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 659 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 660 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 661 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 662 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 663 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 664 | template<typename ParentPool> |
| 665 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 666 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 667 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 668 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 669 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 670 | const std::string last_group_name_received() const { |
| 671 | return last_group_name_; |
| 672 | } |
| 673 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 674 | bool socket_requested() const { return socket_requested_; } |
| 675 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 676 | int RequestSocket(const std::string& group_name, |
| 677 | const void* socket_params, |
| 678 | RequestPriority priority, |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 679 | const SocketTag& socket_tag, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 680 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 681 | ClientSocketHandle* handle, |
| 682 | const CompletionCallback& callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 683 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 684 | last_group_name_ = group_name; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 685 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 686 | return ERR_IO_PENDING; |
| 687 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 688 | void CancelRequest(const std::string& group_name, |
| 689 | ClientSocketHandle* handle) override {} |
| 690 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 691 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 692 | int id) override {} |
| 693 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 694 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 695 | int IdleSocketCount() const override { return 0; } |
| 696 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 697 | return 0; |
| 698 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 699 | LoadState GetLoadState(const std::string& group_name, |
| 700 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 701 | return LOAD_STATE_IDLE; |
| 702 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 703 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 704 | return base::TimeDelta(); |
| 705 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 706 | |
| 707 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 708 | std::string last_group_name_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 709 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 710 | }; |
| 711 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 712 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 713 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 714 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 715 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 716 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 717 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 718 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 719 | CaptureGroupNameSSLSocketPool; |
| 720 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 721 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 722 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 723 | HostResolver* host_resolver, |
| 724 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 725 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 726 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 727 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 728 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 729 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 730 | CertVerifier* /* cert_verifier */) |
tbansal | 16196a1e | 2017-06-09 01:50:09 | [diff] [blame] | 731 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 732 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 733 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 734 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 735 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 736 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 737 | : SSLClientSocketPool(0, |
| 738 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 739 | cert_verifier, |
| 740 | NULL, |
| 741 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 742 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 743 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 744 | std::string(), |
| 745 | NULL, |
| 746 | NULL, |
| 747 | NULL, |
| 748 | NULL, |
| 749 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 750 | NULL) { |
| 751 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 752 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 753 | //----------------------------------------------------------------------------- |
| 754 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 755 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 756 | // configured for common cases. |
| 757 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 758 | if (!auth_challenge) |
| 759 | return false; |
| 760 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 761 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 762 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 763 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 764 | return true; |
| 765 | } |
| 766 | |
| 767 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 768 | if (!auth_challenge) |
| 769 | return false; |
| 770 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 771 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 772 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 773 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 774 | return true; |
| 775 | } |
| 776 | |
| 777 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 778 | if (!auth_challenge) |
| 779 | return false; |
| 780 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 781 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 782 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 783 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 784 | return true; |
| 785 | } |
| 786 | |
| 787 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 788 | if (!auth_challenge) |
| 789 | return false; |
| 790 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 791 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 792 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 793 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 794 | return true; |
| 795 | } |
| 796 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 797 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 798 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 799 | if (!auth_challenge) |
| 800 | return false; |
| 801 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 802 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 803 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 804 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 805 | return true; |
| 806 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 807 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 808 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 809 | } // namespace |
| 810 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 811 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 812 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 814 | } |
| 815 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 816 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 817 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 818 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 819 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 820 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 821 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 822 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 823 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 824 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 825 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 826 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 827 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 828 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 829 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 830 | |
| 831 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 835 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 836 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 837 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 838 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 839 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 840 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 841 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 842 | EXPECT_THAT(out.rv, IsOk()); |
| 843 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 844 | EXPECT_EQ("hello world", out.response_data); |
| 845 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 846 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 847 | } |
| 848 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 849 | // Response with no status line, and a weird port. Should fail by default. |
| 850 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 851 | MockRead data_reads[] = { |
| 852 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 853 | }; |
| 854 | |
| 855 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 856 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 857 | |
| 858 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 859 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 860 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 861 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 862 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 863 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 864 | request.method = "GET"; |
| 865 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 866 | request.traffic_annotation = |
| 867 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 868 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 869 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 870 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 871 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 872 | } |
| 873 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 874 | // Tests that request info can be destroyed after the headers phase is complete. |
| 875 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 876 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 877 | auto trans = |
| 878 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 879 | |
| 880 | MockRead data_reads[] = { |
| 881 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 882 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 883 | }; |
| 884 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 885 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 886 | |
| 887 | TestCompletionCallback callback; |
| 888 | |
| 889 | { |
| 890 | auto request = std::make_unique<HttpRequestInfo>(); |
| 891 | request->method = "GET"; |
| 892 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 893 | request->traffic_annotation = |
| 894 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 895 | |
| 896 | int rv = |
| 897 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 898 | |
| 899 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 900 | } // Let request info be destroyed. |
| 901 | |
| 902 | trans.reset(); |
| 903 | } |
| 904 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 905 | // Response with no status line, and a weird port. Option to allow weird ports |
| 906 | // enabled. |
| 907 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 908 | MockRead data_reads[] = { |
| 909 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 910 | }; |
| 911 | |
| 912 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 913 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 914 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 915 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 916 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 917 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 918 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 919 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 920 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 921 | request.method = "GET"; |
| 922 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 923 | request.traffic_annotation = |
| 924 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 925 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 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/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1219 | request.traffic_annotation = |
| 1220 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1221 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1223 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1224 | |
| 1225 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1226 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1228 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1229 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1230 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1231 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1232 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1233 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1234 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1235 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1236 | ASSERT_TRUE(response); |
| 1237 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1238 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1239 | std::string url; |
| 1240 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1241 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1242 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1243 | } |
| 1244 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1245 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1246 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1247 | MockRead data_reads[] = { |
| 1248 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1249 | MockRead("Location: http://good.com/\r\n"), |
| 1250 | MockRead("Location: http://evil.com/\r\n"), |
| 1251 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1252 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1253 | }; |
| 1254 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1255 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1256 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1257 | } |
| 1258 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1259 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1260 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1261 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1262 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1263 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1264 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1265 | request.traffic_annotation = |
| 1266 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1267 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1268 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1269 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1270 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1271 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1272 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1273 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1274 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1275 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1276 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1277 | "Host: www.example.org\r\n" |
| 1278 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1279 | }; |
| 1280 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1281 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1282 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1283 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1284 | // No response body because the test stops reading here. |
| 1285 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1286 | }; |
| 1287 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1288 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1289 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1290 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1291 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1292 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1293 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1294 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1295 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1296 | |
| 1297 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1298 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1299 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1300 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1301 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1302 | |
| 1303 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1304 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1305 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1306 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1307 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1308 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1309 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1310 | |
| 1311 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1312 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1313 | bool has_server_header = response->headers->EnumerateHeader( |
| 1314 | &iter, "Server", &server_header); |
| 1315 | EXPECT_TRUE(has_server_header); |
| 1316 | EXPECT_EQ("Blah", server_header); |
| 1317 | |
| 1318 | // Reading should give EOF right away, since there is no message body |
| 1319 | // (despite non-zero content-length). |
| 1320 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1321 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1322 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1323 | EXPECT_EQ("", response_data); |
| 1324 | } |
| 1325 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1326 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1327 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1328 | |
| 1329 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1330 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1331 | MockRead("hello"), |
| 1332 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1333 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1334 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1335 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1336 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1337 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1338 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1339 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1340 | "hello", "world" |
| 1341 | }; |
| 1342 | |
| 1343 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1344 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1345 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1346 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1347 | request.traffic_annotation = |
| 1348 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1349 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1350 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1352 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1354 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | |
| 1357 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1358 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1359 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1360 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1361 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1362 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1363 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1364 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1365 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1366 | |
| 1367 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1368 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1369 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1370 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1371 | } |
| 1372 | } |
| 1373 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1374 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1375 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1376 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1377 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1378 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1379 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1380 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1381 | request.method = "POST"; |
| 1382 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1383 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1384 | request.traffic_annotation = |
| 1385 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1386 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1387 | // Check the upload progress returned before initialization is correct. |
| 1388 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1389 | EXPECT_EQ(0u, progress.size()); |
| 1390 | EXPECT_EQ(0u, progress.position()); |
| 1391 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1393 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1394 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1395 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1396 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1397 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1398 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1399 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1400 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1401 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1402 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1403 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1404 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1405 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1406 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1407 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1408 | |
| 1409 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1410 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1411 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1412 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1413 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1414 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1415 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1416 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1417 | |
| 1418 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1419 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1420 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1421 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1422 | } |
| 1423 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1424 | // This test is almost the same as Ignores100 above, but the response contains |
| 1425 | // 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] | 1426 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1427 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1428 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1429 | request.method = "GET"; |
| 1430 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1431 | request.traffic_annotation = |
| 1432 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1433 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1434 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1435 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1436 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1437 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1438 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1439 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1440 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1441 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1442 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1443 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1444 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1445 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1446 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1447 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1448 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1449 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1450 | |
| 1451 | rv = callback.WaitForResult(); |
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 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1454 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1455 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1456 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1457 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1458 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1459 | |
| 1460 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1461 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1462 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1463 | EXPECT_EQ("hello world", response_data); |
| 1464 | } |
| 1465 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1466 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1467 | HttpRequestInfo request; |
| 1468 | request.method = "POST"; |
| 1469 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1470 | request.traffic_annotation = |
| 1471 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1472 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1473 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1474 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1475 | |
| 1476 | MockRead data_reads[] = { |
| 1477 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1478 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1479 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1480 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1481 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1482 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1483 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1484 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1485 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1487 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1488 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1489 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1490 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1491 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1492 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1493 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1494 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1495 | } |
| 1496 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1497 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1498 | HttpRequestInfo request; |
| 1499 | request.method = "POST"; |
| 1500 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1501 | request.traffic_annotation = |
| 1502 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1503 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1504 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1505 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1506 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1507 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1508 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1509 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1510 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1511 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1513 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1514 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1515 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1516 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1517 | |
| 1518 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1519 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1520 | } |
| 1521 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1522 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1523 | const MockWrite* write_failure, |
| 1524 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1525 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1526 | request.method = "GET"; |
| 1527 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1528 | request.traffic_annotation = |
| 1529 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1530 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1531 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1532 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1533 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1534 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1535 | // Written data for successfully sending both requests. |
| 1536 | MockWrite data1_writes[] = { |
| 1537 | MockWrite("GET / HTTP/1.1\r\n" |
| 1538 | "Host: www.foo.com\r\n" |
| 1539 | "Connection: keep-alive\r\n\r\n"), |
| 1540 | MockWrite("GET / HTTP/1.1\r\n" |
| 1541 | "Host: www.foo.com\r\n" |
| 1542 | "Connection: keep-alive\r\n\r\n") |
| 1543 | }; |
| 1544 | |
| 1545 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1546 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1547 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1548 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1549 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1550 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1551 | |
| 1552 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1553 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1554 | data1_writes[1] = *write_failure; |
| 1555 | } else { |
| 1556 | ASSERT_TRUE(read_failure); |
| 1557 | data1_reads[2] = *read_failure; |
| 1558 | } |
| 1559 | |
| 1560 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1561 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1562 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1563 | |
| 1564 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1565 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1566 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1567 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1568 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1569 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1570 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1571 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1572 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1573 | "hello", "world" |
| 1574 | }; |
| 1575 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1576 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1577 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1578 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1579 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1580 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1581 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1582 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1584 | |
| 1585 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1586 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1587 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1588 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1589 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1590 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1591 | if (i == 0) { |
| 1592 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1593 | } else { |
| 1594 | // The second request should be using a new socket. |
| 1595 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1596 | } |
| 1597 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1598 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1599 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1600 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1601 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1602 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1603 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1604 | |
| 1605 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1606 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1607 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1608 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1609 | } |
| 1610 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1611 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1612 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1613 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1614 | const MockRead* read_failure, |
| 1615 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1616 | HttpRequestInfo request; |
| 1617 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1618 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1619 | request.traffic_annotation = |
| 1620 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1621 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1622 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1623 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1624 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1625 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1626 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1627 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1628 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1629 | ssl1.next_proto = kProtoHTTP2; |
| 1630 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1631 | } |
| 1632 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1633 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1634 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1635 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1636 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1637 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1638 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1639 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1640 | SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1641 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1642 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1643 | // HTTP/1.1 versions of the request and response. |
| 1644 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1645 | "Host: www.foo.com\r\n" |
| 1646 | "Connection: keep-alive\r\n\r\n"; |
| 1647 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1648 | const char kHttpData[] = "hello"; |
| 1649 | |
| 1650 | std::vector<MockRead> data1_reads; |
| 1651 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1652 | if (write_failure) { |
| 1653 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1654 | data1_writes.push_back(*write_failure); |
| 1655 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1656 | } else { |
| 1657 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1658 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1659 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1660 | } else { |
| 1661 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1662 | } |
| 1663 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1664 | } |
| 1665 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1666 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1667 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1668 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1669 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1670 | std::vector<MockRead> data2_reads; |
| 1671 | std::vector<MockWrite> data2_writes; |
| 1672 | |
| 1673 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1674 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1675 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1676 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1677 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1678 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1679 | } else { |
| 1680 | data2_writes.push_back( |
| 1681 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1682 | |
| 1683 | data2_reads.push_back( |
| 1684 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1685 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1686 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1687 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1688 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1689 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1690 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1691 | |
| 1692 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1693 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1694 | // Wait for the preconnect to complete. |
| 1695 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1696 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1697 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1698 | |
| 1699 | // Make the request. |
| 1700 | TestCompletionCallback callback; |
| 1701 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1702 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1703 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1704 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1705 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1706 | |
| 1707 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1708 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1709 | |
| 1710 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1711 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1712 | TestLoadTimingNotReused( |
| 1713 | load_timing_info, |
| 1714 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1715 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1716 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1717 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1718 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1719 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1720 | if (response->was_fetched_via_spdy) { |
| 1721 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1722 | } else { |
| 1723 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1724 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1725 | |
| 1726 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1727 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1728 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1729 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1730 | } |
| 1731 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1732 | // Test that we do not retry indefinitely when a server sends an error like |
| 1733 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1734 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1735 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1736 | HttpRequestInfo request; |
| 1737 | request.method = "GET"; |
| 1738 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1739 | request.traffic_annotation = |
| 1740 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1741 | |
| 1742 | // Check whether we give up after the third try. |
| 1743 | |
| 1744 | // Construct an HTTP2 request and a "Go away" response. |
| 1745 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1746 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Bence Béky | dcb3009 | 2018-02-11 01:32:29 | [diff] [blame] | 1747 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway(0)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1748 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1749 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1750 | |
| 1751 | // Three go away responses. |
| 1752 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1753 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1754 | StaticSocketDataProvider data3(&data_read1, 1, &data_write, 1); |
| 1755 | |
| 1756 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1757 | AddSSLSocketData(); |
| 1758 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1759 | AddSSLSocketData(); |
| 1760 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1761 | AddSSLSocketData(); |
| 1762 | |
| 1763 | TestCompletionCallback callback; |
| 1764 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1765 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1766 | |
| 1767 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1768 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1769 | |
| 1770 | rv = callback.WaitForResult(); |
| 1771 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1772 | } |
| 1773 | |
| 1774 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1775 | HttpRequestInfo request; |
| 1776 | request.method = "GET"; |
| 1777 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1778 | request.traffic_annotation = |
| 1779 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1780 | |
| 1781 | // Check whether we try atleast thrice before giving up. |
| 1782 | |
| 1783 | // Construct an HTTP2 request and a "Go away" response. |
| 1784 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1785 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Bence Béky | dcb3009 | 2018-02-11 01:32:29 | [diff] [blame] | 1786 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway(0)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1787 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1788 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1789 | |
| 1790 | // Construct a non error HTTP2 response. |
| 1791 | SpdySerializedFrame spdy_response_no_error( |
| 1792 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1793 | SpdySerializedFrame spdy_data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 1794 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1795 | CreateMockRead(spdy_data, 2)}; |
| 1796 | |
| 1797 | // Two error responses. |
| 1798 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1799 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1800 | // Followed by a success response. |
| 1801 | SequencedSocketData data3(data_read2, 2, &data_write, 1); |
| 1802 | |
| 1803 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1804 | AddSSLSocketData(); |
| 1805 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1806 | AddSSLSocketData(); |
| 1807 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1808 | AddSSLSocketData(); |
| 1809 | |
| 1810 | TestCompletionCallback callback; |
| 1811 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1812 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1813 | |
| 1814 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1816 | |
| 1817 | rv = callback.WaitForResult(); |
| 1818 | EXPECT_THAT(rv, IsOk()); |
| 1819 | } |
| 1820 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1821 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1822 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1823 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1824 | } |
| 1825 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1826 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1827 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1828 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1829 | } |
| 1830 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1831 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1832 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1833 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1834 | } |
| 1835 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1836 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1837 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1838 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1839 | MockRead read_failure(SYNCHRONOUS, |
| 1840 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1841 | "Connection: Keep-Alive\r\n" |
| 1842 | "Content-Length: 6\r\n\r\n" |
| 1843 | "Pickle"); |
| 1844 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1845 | } |
| 1846 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1847 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1848 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1849 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1850 | } |
| 1851 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1852 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1853 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1854 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1855 | } |
| 1856 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1857 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1858 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1859 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1860 | } |
| 1861 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1862 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1863 | MockRead read_failure(ASYNC, OK); // EOF |
| 1864 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1865 | } |
| 1866 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1867 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1868 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1869 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1870 | MockRead read_failure(SYNCHRONOUS, |
| 1871 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1872 | "Connection: Keep-Alive\r\n" |
| 1873 | "Content-Length: 6\r\n\r\n" |
| 1874 | "Pickle"); |
| 1875 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1876 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1877 | } |
| 1878 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1879 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1880 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1881 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1882 | } |
| 1883 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1884 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1885 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1886 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1887 | } |
| 1888 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1889 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1890 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1891 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1892 | } |
| 1893 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1894 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1895 | MockRead read_failure(ASYNC, OK); // EOF |
| 1896 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1897 | } |
| 1898 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1899 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1900 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1901 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1902 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1903 | request.traffic_annotation = |
| 1904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1905 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1907 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1908 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1909 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1910 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1911 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1912 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1913 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1914 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1915 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1916 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1917 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1918 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1919 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1920 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1921 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1922 | |
| 1923 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1924 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1925 | |
| 1926 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1927 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1928 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | // What do various browsers do when the server closes a non-keepalive |
| 1932 | // connection without sending any response header or body? |
| 1933 | // |
| 1934 | // IE7: error page |
| 1935 | // Safari 3.1.2 (Windows): error page |
| 1936 | // Firefox 3.0.1: blank page |
| 1937 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1938 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1939 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1940 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1941 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1942 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1943 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1944 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1945 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1946 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1947 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1948 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1949 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1950 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1951 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1952 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1953 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1954 | // destructor in such situations. |
| 1955 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1956 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1957 | HttpRequestInfo request; |
| 1958 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1959 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1960 | request.traffic_annotation = |
| 1961 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1962 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1963 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1964 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1965 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1966 | |
| 1967 | MockRead data_reads[] = { |
| 1968 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1969 | MockRead("Connection: keep-alive\r\n"), |
| 1970 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1971 | MockRead("hello"), |
| 1972 | MockRead(SYNCHRONOUS, 0), |
| 1973 | }; |
| 1974 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1975 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1976 | |
| 1977 | TestCompletionCallback callback; |
| 1978 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1979 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1980 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1981 | |
| 1982 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1983 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1984 | |
| 1985 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1986 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1987 | if (rv == ERR_IO_PENDING) |
| 1988 | rv = callback.WaitForResult(); |
| 1989 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1990 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1991 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1992 | |
| 1993 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1994 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1995 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1996 | } |
| 1997 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1998 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1999 | HttpRequestInfo request; |
| 2000 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2001 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2002 | request.traffic_annotation = |
| 2003 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2004 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2005 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2006 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2007 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2008 | |
| 2009 | MockRead data_reads[] = { |
| 2010 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2011 | MockRead("Connection: keep-alive\r\n"), |
| 2012 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2013 | MockRead(SYNCHRONOUS, 0), |
| 2014 | }; |
| 2015 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2016 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2017 | |
| 2018 | TestCompletionCallback callback; |
| 2019 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2020 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2021 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2022 | |
| 2023 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2024 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2025 | |
| 2026 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2027 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2028 | if (rv == ERR_IO_PENDING) |
| 2029 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2030 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2031 | |
| 2032 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2033 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2034 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2035 | } |
| 2036 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2037 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2038 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2039 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2040 | HttpRequestInfo request; |
| 2041 | request.method = "GET"; |
| 2042 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2043 | request.traffic_annotation = |
| 2044 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2045 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2046 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2047 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2048 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2049 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2050 | const char* request_data = |
| 2051 | "GET / HTTP/1.1\r\n" |
| 2052 | "Host: www.foo.com\r\n" |
| 2053 | "Connection: keep-alive\r\n\r\n"; |
| 2054 | MockWrite data_writes[] = { |
| 2055 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2056 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2057 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2058 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2059 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2060 | }; |
| 2061 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2062 | // Note that because all these reads happen in the same |
| 2063 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2064 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2065 | MockRead data_reads[] = { |
| 2066 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2067 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2068 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2069 | MockRead(ASYNC, 7, |
| 2070 | "HTTP/1.1 302 Found\r\n" |
| 2071 | "Content-Length: 0\r\n\r\n"), |
| 2072 | MockRead(ASYNC, 9, |
| 2073 | "HTTP/1.1 302 Found\r\n" |
| 2074 | "Content-Length: 5\r\n\r\n" |
| 2075 | "hello"), |
| 2076 | MockRead(ASYNC, 11, |
| 2077 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2078 | "Content-Length: 0\r\n\r\n"), |
| 2079 | MockRead(ASYNC, 13, |
| 2080 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2081 | "Content-Length: 5\r\n\r\n" |
| 2082 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2083 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2084 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2085 | // the set_busy_before_sync_reads(true) call, while the |
| 2086 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2087 | // reuseable. See http://crbug.com/544255. |
| 2088 | MockRead(ASYNC, 15, |
| 2089 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2090 | "Content-Length: 5\r\n\r\n"), |
| 2091 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2092 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2093 | MockRead(ASYNC, 18, |
| 2094 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2095 | "Content-Length: 5\r\n\r\n" |
| 2096 | "he"), |
| 2097 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2098 | |
| 2099 | // The body of the final request is actually read. |
| 2100 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2101 | MockRead(ASYNC, 22, "hello"), |
| 2102 | }; |
| 2103 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2104 | arraysize(data_writes)); |
| 2105 | data.set_busy_before_sync_reads(true); |
| 2106 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2107 | |
| 2108 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2109 | std::string response_lines[kNumUnreadBodies]; |
| 2110 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2111 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2112 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2113 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2114 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2115 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2116 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2117 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2118 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2119 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2120 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2121 | LoadTimingInfo load_timing_info; |
| 2122 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2123 | if (i == 0) { |
| 2124 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2125 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2126 | } else { |
| 2127 | TestLoadTimingReused(load_timing_info); |
| 2128 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2129 | } |
| 2130 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2131 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2132 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2133 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2134 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2135 | response_lines[i] = response->headers->GetStatusLine(); |
| 2136 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2137 | // Delete the transaction without reading the response bodies. Then spin |
| 2138 | // the message loop, so the response bodies are drained. |
| 2139 | trans.reset(); |
| 2140 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2141 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2142 | |
| 2143 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2144 | "HTTP/1.1 204 No Content", |
| 2145 | "HTTP/1.1 205 Reset Content", |
| 2146 | "HTTP/1.1 304 Not Modified", |
| 2147 | "HTTP/1.1 302 Found", |
| 2148 | "HTTP/1.1 302 Found", |
| 2149 | "HTTP/1.1 301 Moved Permanently", |
| 2150 | "HTTP/1.1 301 Moved Permanently", |
| 2151 | "HTTP/1.1 200 Hunky-Dory", |
| 2152 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2153 | }; |
| 2154 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2155 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2156 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2157 | |
| 2158 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2159 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2160 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2161 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2162 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2163 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2164 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2165 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2166 | ASSERT_TRUE(response); |
| 2167 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2168 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2169 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2170 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2171 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2172 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2173 | } |
| 2174 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2175 | // Sockets that receive extra data after a response is complete should not be |
| 2176 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2177 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2179 | MockWrite data_writes1[] = { |
| 2180 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2181 | "Host: www.borked.com\r\n" |
| 2182 | "Connection: keep-alive\r\n\r\n"), |
| 2183 | }; |
| 2184 | |
| 2185 | MockRead data_reads1[] = { |
| 2186 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2187 | "Connection: keep-alive\r\n" |
| 2188 | "Content-Length: 22\r\n\r\n" |
| 2189 | "This server is borked."), |
| 2190 | }; |
| 2191 | |
| 2192 | MockWrite data_writes2[] = { |
| 2193 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2194 | "Host: www.borked.com\r\n" |
| 2195 | "Connection: keep-alive\r\n\r\n"), |
| 2196 | }; |
| 2197 | |
| 2198 | MockRead data_reads2[] = { |
| 2199 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2200 | "Content-Length: 3\r\n\r\n" |
| 2201 | "foo"), |
| 2202 | }; |
| 2203 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2204 | data_writes1, arraysize(data_writes1)); |
| 2205 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2206 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2207 | data_writes2, arraysize(data_writes2)); |
| 2208 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2209 | |
| 2210 | TestCompletionCallback callback; |
| 2211 | HttpRequestInfo request1; |
| 2212 | request1.method = "HEAD"; |
| 2213 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2214 | request1.traffic_annotation = |
| 2215 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2216 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2217 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2218 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2219 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2220 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2221 | |
| 2222 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2223 | ASSERT_TRUE(response1); |
| 2224 | ASSERT_TRUE(response1->headers); |
| 2225 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2226 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2227 | |
| 2228 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2229 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2230 | EXPECT_EQ("", response_data1); |
| 2231 | // Deleting the transaction attempts to release the socket back into the |
| 2232 | // socket pool. |
| 2233 | trans1.reset(); |
| 2234 | |
| 2235 | HttpRequestInfo request2; |
| 2236 | request2.method = "GET"; |
| 2237 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2238 | request2.traffic_annotation = |
| 2239 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2240 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2241 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2242 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2243 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2244 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2245 | |
| 2246 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2247 | ASSERT_TRUE(response2); |
| 2248 | ASSERT_TRUE(response2->headers); |
| 2249 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2250 | |
| 2251 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2252 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2253 | EXPECT_EQ("foo", response_data2); |
| 2254 | } |
| 2255 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2256 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2257 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2258 | MockWrite data_writes1[] = { |
| 2259 | MockWrite("GET / HTTP/1.1\r\n" |
| 2260 | "Host: www.borked.com\r\n" |
| 2261 | "Connection: keep-alive\r\n\r\n"), |
| 2262 | }; |
| 2263 | |
| 2264 | MockRead data_reads1[] = { |
| 2265 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2266 | "Connection: keep-alive\r\n" |
| 2267 | "Content-Length: 22\r\n\r\n" |
| 2268 | "This server is borked." |
| 2269 | "Bonus data!"), |
| 2270 | }; |
| 2271 | |
| 2272 | MockWrite data_writes2[] = { |
| 2273 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2274 | "Host: www.borked.com\r\n" |
| 2275 | "Connection: keep-alive\r\n\r\n"), |
| 2276 | }; |
| 2277 | |
| 2278 | MockRead data_reads2[] = { |
| 2279 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2280 | "Content-Length: 3\r\n\r\n" |
| 2281 | "foo"), |
| 2282 | }; |
| 2283 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2284 | data_writes1, arraysize(data_writes1)); |
| 2285 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2286 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2287 | data_writes2, arraysize(data_writes2)); |
| 2288 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2289 | |
| 2290 | TestCompletionCallback callback; |
| 2291 | HttpRequestInfo request1; |
| 2292 | request1.method = "GET"; |
| 2293 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2294 | request1.traffic_annotation = |
| 2295 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2296 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2297 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2298 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2299 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2300 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2301 | |
| 2302 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2303 | ASSERT_TRUE(response1); |
| 2304 | ASSERT_TRUE(response1->headers); |
| 2305 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2306 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2307 | |
| 2308 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2309 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2310 | EXPECT_EQ("This server is borked.", response_data1); |
| 2311 | // Deleting the transaction attempts to release the socket back into the |
| 2312 | // socket pool. |
| 2313 | trans1.reset(); |
| 2314 | |
| 2315 | HttpRequestInfo request2; |
| 2316 | request2.method = "GET"; |
| 2317 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2318 | request2.traffic_annotation = |
| 2319 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2320 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2321 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2322 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2323 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2324 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2325 | |
| 2326 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2327 | ASSERT_TRUE(response2); |
| 2328 | ASSERT_TRUE(response2->headers); |
| 2329 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2330 | |
| 2331 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2332 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2333 | EXPECT_EQ("foo", response_data2); |
| 2334 | } |
| 2335 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2336 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2337 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2338 | MockWrite data_writes1[] = { |
| 2339 | MockWrite("GET / HTTP/1.1\r\n" |
| 2340 | "Host: www.borked.com\r\n" |
| 2341 | "Connection: keep-alive\r\n\r\n"), |
| 2342 | }; |
| 2343 | |
| 2344 | MockRead data_reads1[] = { |
| 2345 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2346 | "Connection: keep-alive\r\n" |
| 2347 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2348 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2349 | MockRead("0\r\n\r\nBonus data!"), |
| 2350 | }; |
| 2351 | |
| 2352 | MockWrite data_writes2[] = { |
| 2353 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2354 | "Host: www.borked.com\r\n" |
| 2355 | "Connection: keep-alive\r\n\r\n"), |
| 2356 | }; |
| 2357 | |
| 2358 | MockRead data_reads2[] = { |
| 2359 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2360 | "Content-Length: 3\r\n\r\n" |
| 2361 | "foo"), |
| 2362 | }; |
| 2363 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2364 | data_writes1, arraysize(data_writes1)); |
| 2365 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2366 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2367 | data_writes2, arraysize(data_writes2)); |
| 2368 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2369 | |
| 2370 | TestCompletionCallback callback; |
| 2371 | HttpRequestInfo request1; |
| 2372 | request1.method = "GET"; |
| 2373 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2374 | request1.traffic_annotation = |
| 2375 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2376 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2377 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2378 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2379 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2380 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2381 | |
| 2382 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2383 | ASSERT_TRUE(response1); |
| 2384 | ASSERT_TRUE(response1->headers); |
| 2385 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2386 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2387 | |
| 2388 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2389 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2390 | EXPECT_EQ("This server is borked.", response_data1); |
| 2391 | // Deleting the transaction attempts to release the socket back into the |
| 2392 | // socket pool. |
| 2393 | trans1.reset(); |
| 2394 | |
| 2395 | HttpRequestInfo request2; |
| 2396 | request2.method = "GET"; |
| 2397 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2398 | request2.traffic_annotation = |
| 2399 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2400 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2401 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2402 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2403 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2404 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2405 | |
| 2406 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2407 | ASSERT_TRUE(response2); |
| 2408 | ASSERT_TRUE(response2->headers); |
| 2409 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2410 | |
| 2411 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2412 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2413 | EXPECT_EQ("foo", response_data2); |
| 2414 | } |
| 2415 | |
| 2416 | // This is a little different from the others - it tests the case that the |
| 2417 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2418 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2419 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2420 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2422 | MockWrite data_writes1[] = { |
| 2423 | MockWrite("GET / HTTP/1.1\r\n" |
| 2424 | "Host: www.borked.com\r\n" |
| 2425 | "Connection: keep-alive\r\n\r\n"), |
| 2426 | }; |
| 2427 | |
| 2428 | MockRead data_reads1[] = { |
| 2429 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2430 | "Connection: keep-alive\r\n" |
| 2431 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2432 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2433 | MockRead("0\r\n\r\nBonus data!"), |
| 2434 | }; |
| 2435 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2436 | data_writes1, arraysize(data_writes1)); |
| 2437 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2438 | |
| 2439 | TestCompletionCallback callback; |
| 2440 | HttpRequestInfo request1; |
| 2441 | request1.method = "GET"; |
| 2442 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2443 | request1.traffic_annotation = |
| 2444 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2445 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2446 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2447 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2448 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2449 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2450 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2451 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2452 | ASSERT_TRUE(response1); |
| 2453 | ASSERT_TRUE(response1->headers); |
| 2454 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2455 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2456 | |
| 2457 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2458 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2459 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2460 | |
| 2461 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2462 | // socket can't be reused, rather than returning it to the socket pool. |
| 2463 | base::RunLoop().RunUntilIdle(); |
| 2464 | |
| 2465 | // There should be no idle sockets in the pool. |
| 2466 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2467 | } |
| 2468 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2469 | // Test the request-challenge-retry sequence for basic auth. |
| 2470 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2471 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2472 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2473 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2474 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2475 | request.traffic_annotation = |
| 2476 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2477 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2478 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2479 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2480 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2481 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2482 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2483 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2484 | MockWrite( |
| 2485 | "GET / HTTP/1.1\r\n" |
| 2486 | "Host: www.example.org\r\n" |
| 2487 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2488 | }; |
| 2489 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2490 | MockRead data_reads1[] = { |
| 2491 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2492 | // Give a couple authenticate options (only the middle one is actually |
| 2493 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2494 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2495 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2496 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2497 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2498 | // Large content-length -- won't matter, as connection will be reset. |
| 2499 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2500 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2501 | }; |
| 2502 | |
| 2503 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2504 | // be issuing -- the final header line contains the credentials. |
| 2505 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2506 | MockWrite( |
| 2507 | "GET / HTTP/1.1\r\n" |
| 2508 | "Host: www.example.org\r\n" |
| 2509 | "Connection: keep-alive\r\n" |
| 2510 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2511 | }; |
| 2512 | |
| 2513 | // Lastly, the server responds with the actual content. |
| 2514 | MockRead data_reads2[] = { |
| 2515 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2516 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2517 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2518 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2519 | }; |
| 2520 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2521 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2522 | data_writes1, arraysize(data_writes1)); |
| 2523 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2524 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2525 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2526 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2527 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2528 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2529 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2530 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2531 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2532 | |
| 2533 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2534 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2535 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2536 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2537 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2538 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2539 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2540 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2541 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2542 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2543 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2544 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2545 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2546 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2547 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2548 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2549 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2551 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2552 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2553 | |
| 2554 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2555 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2556 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2557 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2558 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2559 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2560 | // The load timing after restart should have a new socket ID, and times after |
| 2561 | // those of the first load timing. |
| 2562 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2563 | load_timing_info2.connect_timing.connect_start); |
| 2564 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2565 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2566 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2567 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2568 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2569 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2570 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2571 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2572 | ASSERT_TRUE(response); |
| 2573 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2574 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2575 | } |
| 2576 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2577 | // Test the request-challenge-retry sequence for basic auth. |
| 2578 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2579 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2580 | HttpRequestInfo request; |
| 2581 | request.method = "GET"; |
| 2582 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2583 | request.traffic_annotation = |
| 2584 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2585 | |
| 2586 | TestNetLog log; |
| 2587 | MockHostResolver* resolver = new MockHostResolver(); |
| 2588 | session_deps_.net_log = &log; |
| 2589 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2590 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2591 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2592 | |
| 2593 | resolver->rules()->ClearRules(); |
| 2594 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2595 | |
| 2596 | MockWrite data_writes1[] = { |
| 2597 | MockWrite("GET / HTTP/1.1\r\n" |
| 2598 | "Host: www.example.org\r\n" |
| 2599 | "Connection: keep-alive\r\n\r\n"), |
| 2600 | }; |
| 2601 | |
| 2602 | MockRead data_reads1[] = { |
| 2603 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2604 | // Give a couple authenticate options (only the middle one is actually |
| 2605 | // supported). |
| 2606 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2607 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2608 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2609 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2610 | // Large content-length -- won't matter, as connection will be reset. |
| 2611 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2612 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2613 | }; |
| 2614 | |
| 2615 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2616 | // be issuing -- the final header line contains the credentials. |
| 2617 | MockWrite data_writes2[] = { |
| 2618 | MockWrite("GET / HTTP/1.1\r\n" |
| 2619 | "Host: www.example.org\r\n" |
| 2620 | "Connection: keep-alive\r\n" |
| 2621 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2622 | }; |
| 2623 | |
| 2624 | // Lastly, the server responds with the actual content. |
| 2625 | MockRead data_reads2[] = { |
| 2626 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2627 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2628 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2629 | }; |
| 2630 | |
| 2631 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2632 | data_writes1, arraysize(data_writes1)); |
| 2633 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2634 | data_writes2, arraysize(data_writes2)); |
| 2635 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2636 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2637 | |
| 2638 | TestCompletionCallback callback1; |
| 2639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2640 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2641 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2642 | |
| 2643 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2644 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2645 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2646 | |
| 2647 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2648 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2649 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2650 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2651 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2652 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2653 | ASSERT_TRUE(response); |
| 2654 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2655 | |
| 2656 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2657 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2658 | ASSERT_FALSE(endpoint.address().empty()); |
| 2659 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2660 | |
| 2661 | resolver->rules()->ClearRules(); |
| 2662 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2663 | |
| 2664 | TestCompletionCallback callback2; |
| 2665 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2666 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2667 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2668 | |
| 2669 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2670 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2671 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2672 | // The load timing after restart should have a new socket ID, and times after |
| 2673 | // those of the first load timing. |
| 2674 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2675 | load_timing_info2.connect_timing.connect_start); |
| 2676 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2677 | |
| 2678 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2679 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2680 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2681 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2683 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2684 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2685 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2686 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2687 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2688 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2689 | ASSERT_FALSE(endpoint.address().empty()); |
| 2690 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2691 | } |
| 2692 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame^] | 2693 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2694 | // will eventually give up. |
| 2695 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2696 | HttpRequestInfo request; |
| 2697 | request.method = "GET"; |
| 2698 | request.url = GURL("http://www.example.org/"); |
| 2699 | request.traffic_annotation = |
| 2700 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2701 | |
| 2702 | TestNetLog log; |
| 2703 | session_deps_.net_log = &log; |
| 2704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2705 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2706 | |
| 2707 | MockWrite data_writes[] = { |
| 2708 | MockWrite("GET / HTTP/1.1\r\n" |
| 2709 | "Host: www.example.org\r\n" |
| 2710 | "Connection: keep-alive\r\n\r\n"), |
| 2711 | }; |
| 2712 | |
| 2713 | MockRead data_reads[] = { |
| 2714 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2715 | // Give a couple authenticate options (only the middle one is actually |
| 2716 | // supported). |
| 2717 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2718 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2719 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2720 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2721 | // Large content-length -- won't matter, as connection will be reset. |
| 2722 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2723 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2724 | }; |
| 2725 | |
| 2726 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2727 | // be issuing -- the final header line contains the credentials. |
| 2728 | MockWrite data_writes_restart[] = { |
| 2729 | MockWrite("GET / HTTP/1.1\r\n" |
| 2730 | "Host: www.example.org\r\n" |
| 2731 | "Connection: keep-alive\r\n" |
| 2732 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2733 | }; |
| 2734 | |
| 2735 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 2736 | arraysize(data_writes)); |
| 2737 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2738 | |
| 2739 | TestCompletionCallback callback; |
| 2740 | int rv = callback.GetResult( |
| 2741 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2742 | |
| 2743 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2744 | for (int i = 0; i < 32; i++) { |
| 2745 | // Check the previous response was a 401. |
| 2746 | EXPECT_THAT(rv, IsOk()); |
| 2747 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2748 | ASSERT_TRUE(response); |
| 2749 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2750 | |
| 2751 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
| 2752 | data_reads, arraysize(data_reads), data_writes_restart, |
| 2753 | arraysize(data_writes_restart))); |
| 2754 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2755 | data_restarts.back().get()); |
| 2756 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2757 | callback.callback())); |
| 2758 | } |
| 2759 | |
| 2760 | // After too many tries, the transaction should have given up. |
| 2761 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2762 | } |
| 2763 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2764 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2765 | HttpRequestInfo request; |
| 2766 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2767 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2768 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2769 | request.traffic_annotation = |
| 2770 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2771 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2772 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2773 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2774 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2775 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2776 | MockWrite( |
| 2777 | "GET / HTTP/1.1\r\n" |
| 2778 | "Host: www.example.org\r\n" |
| 2779 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2780 | }; |
| 2781 | |
| 2782 | MockRead data_reads[] = { |
| 2783 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2784 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2785 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2786 | // Large content-length -- won't matter, as connection will be reset. |
| 2787 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2788 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2789 | }; |
| 2790 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2791 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2792 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2793 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2794 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2795 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2796 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2797 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2798 | |
| 2799 | rv = callback.WaitForResult(); |
| 2800 | EXPECT_EQ(0, rv); |
| 2801 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2802 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2803 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2804 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2805 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2806 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2807 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2808 | ASSERT_TRUE(response); |
| 2809 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2810 | } |
| 2811 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2812 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2813 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2814 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2815 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2816 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2817 | // reused. See http://crbug.com/544255. |
| 2818 | for (int i = 0; i < 2; ++i) { |
| 2819 | HttpRequestInfo request; |
| 2820 | request.method = "GET"; |
| 2821 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2822 | request.traffic_annotation = |
| 2823 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2824 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2825 | TestNetLog log; |
| 2826 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2828 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2829 | MockWrite data_writes[] = { |
| 2830 | MockWrite(ASYNC, 0, |
| 2831 | "GET / HTTP/1.1\r\n" |
| 2832 | "Host: www.example.org\r\n" |
| 2833 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2835 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2836 | // be issuing -- the final header line contains the credentials. |
| 2837 | MockWrite(ASYNC, 6, |
| 2838 | "GET / HTTP/1.1\r\n" |
| 2839 | "Host: www.example.org\r\n" |
| 2840 | "Connection: keep-alive\r\n" |
| 2841 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2842 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2843 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2844 | MockRead data_reads[] = { |
| 2845 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2846 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2847 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2848 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2849 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2850 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2851 | // Lastly, the server responds with the actual content. |
| 2852 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2853 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2854 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2855 | MockRead(ASYNC, 10, "Hello"), |
| 2856 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2857 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2858 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2859 | arraysize(data_writes)); |
| 2860 | data.set_busy_before_sync_reads(true); |
| 2861 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2862 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2863 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2864 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2865 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2866 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2867 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2868 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2869 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2870 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2871 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2872 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2873 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2874 | ASSERT_TRUE(response); |
| 2875 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2876 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2877 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2878 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2879 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2880 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2881 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2882 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2883 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2884 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2885 | TestLoadTimingReused(load_timing_info2); |
| 2886 | // The load timing after restart should have the same socket ID, and times |
| 2887 | // those of the first load timing. |
| 2888 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2889 | load_timing_info2.send_start); |
| 2890 | 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] | 2891 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2892 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2893 | ASSERT_TRUE(response); |
| 2894 | EXPECT_FALSE(response->auth_challenge); |
| 2895 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2896 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2897 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2898 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2899 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2900 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2901 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2902 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2903 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2904 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2908 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2909 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2910 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2911 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2912 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2913 | request.traffic_annotation = |
| 2914 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2915 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2916 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2917 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2918 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2919 | MockWrite("GET / HTTP/1.1\r\n" |
| 2920 | "Host: www.example.org\r\n" |
| 2921 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2922 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2923 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2924 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2925 | MockWrite("GET / HTTP/1.1\r\n" |
| 2926 | "Host: www.example.org\r\n" |
| 2927 | "Connection: keep-alive\r\n" |
| 2928 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2929 | }; |
| 2930 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2931 | MockRead data_reads1[] = { |
| 2932 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2933 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2934 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2935 | |
| 2936 | // Lastly, the server responds with the actual content. |
| 2937 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2938 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2939 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2940 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2941 | }; |
| 2942 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2943 | // An incorrect reconnect would cause this to be read. |
| 2944 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2945 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2946 | }; |
| 2947 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2948 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2949 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2950 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2951 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2952 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2953 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2954 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2955 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2956 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2957 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2958 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2960 | |
| 2961 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2962 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2963 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2964 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2965 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2966 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2967 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2968 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2969 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2970 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2971 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2972 | |
| 2973 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2974 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2975 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2976 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2977 | ASSERT_TRUE(response); |
| 2978 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2979 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2983 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2984 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2985 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2986 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2987 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2988 | request.traffic_annotation = |
| 2989 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2990 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2991 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2992 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2993 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2994 | MockWrite("GET / HTTP/1.1\r\n" |
| 2995 | "Host: www.example.org\r\n" |
| 2996 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2998 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2999 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3000 | MockWrite("GET / HTTP/1.1\r\n" |
| 3001 | "Host: www.example.org\r\n" |
| 3002 | "Connection: keep-alive\r\n" |
| 3003 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3004 | }; |
| 3005 | |
| 3006 | // Respond with 5 kb of response body. |
| 3007 | std::string large_body_string("Unauthorized"); |
| 3008 | large_body_string.append(5 * 1024, ' '); |
| 3009 | large_body_string.append("\r\n"); |
| 3010 | |
| 3011 | MockRead data_reads1[] = { |
| 3012 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3013 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3014 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3015 | // 5134 = 12 + 5 * 1024 + 2 |
| 3016 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3017 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3018 | |
| 3019 | // Lastly, the server responds with the actual content. |
| 3020 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3021 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3022 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3023 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3024 | }; |
| 3025 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3026 | // An incorrect reconnect would cause this to be read. |
| 3027 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3028 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3029 | }; |
| 3030 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3031 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3032 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3033 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3034 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3035 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3036 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3037 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3038 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3039 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3040 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3041 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3042 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3043 | |
| 3044 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3045 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3046 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3047 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3048 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3049 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3050 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3051 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3052 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3053 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3054 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3055 | |
| 3056 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3057 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3058 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3059 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3060 | ASSERT_TRUE(response); |
| 3061 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3062 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3066 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3067 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3068 | HttpRequestInfo request; |
| 3069 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3070 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3071 | request.traffic_annotation = |
| 3072 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3073 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3074 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3075 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3076 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3077 | MockWrite( |
| 3078 | "GET / HTTP/1.1\r\n" |
| 3079 | "Host: www.example.org\r\n" |
| 3080 | "Connection: keep-alive\r\n\r\n"), |
| 3081 | // This simulates the seemingly successful write to a closed connection |
| 3082 | // if the bug is not fixed. |
| 3083 | MockWrite( |
| 3084 | "GET / HTTP/1.1\r\n" |
| 3085 | "Host: www.example.org\r\n" |
| 3086 | "Connection: keep-alive\r\n" |
| 3087 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3088 | }; |
| 3089 | |
| 3090 | MockRead data_reads1[] = { |
| 3091 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3092 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3093 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3094 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3095 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3096 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3097 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3098 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3099 | }; |
| 3100 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3101 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3102 | // be issuing -- the final header line contains the credentials. |
| 3103 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3104 | MockWrite( |
| 3105 | "GET / HTTP/1.1\r\n" |
| 3106 | "Host: www.example.org\r\n" |
| 3107 | "Connection: keep-alive\r\n" |
| 3108 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3109 | }; |
| 3110 | |
| 3111 | // Lastly, the server responds with the actual content. |
| 3112 | MockRead data_reads2[] = { |
| 3113 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3114 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3115 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3116 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3117 | }; |
| 3118 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3119 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3120 | data_writes1, arraysize(data_writes1)); |
| 3121 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3122 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3123 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3124 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3125 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3126 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3127 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3128 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3129 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3130 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3131 | |
| 3132 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3133 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3134 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3135 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3136 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3137 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3138 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3139 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3140 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3141 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3142 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3143 | |
| 3144 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3145 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3147 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3148 | ASSERT_TRUE(response); |
| 3149 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3150 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3151 | } |
| 3152 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3153 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3154 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3155 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3156 | HttpRequestInfo request; |
| 3157 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3158 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3159 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3160 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3161 | request.traffic_annotation = |
| 3162 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3163 | |
| 3164 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3165 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3166 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3167 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3168 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3169 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3170 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3171 | |
| 3172 | // Since we have proxy, should try to establish tunnel. |
| 3173 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3174 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3175 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3176 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3177 | }; |
| 3178 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3179 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3180 | // connection. |
| 3181 | MockRead data_reads1[] = { |
| 3182 | // No credentials. |
| 3183 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3184 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3185 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3186 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3187 | // Since the first connection couldn't be reused, need to establish another |
| 3188 | // once given credentials. |
| 3189 | MockWrite data_writes2[] = { |
| 3190 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3191 | // be issuing -- the final header line contains the credentials. |
| 3192 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3193 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3194 | "Proxy-Connection: keep-alive\r\n" |
| 3195 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3196 | |
| 3197 | MockWrite("GET / HTTP/1.1\r\n" |
| 3198 | "Host: www.example.org\r\n" |
| 3199 | "Connection: keep-alive\r\n\r\n"), |
| 3200 | }; |
| 3201 | |
| 3202 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3203 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3204 | |
| 3205 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3206 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3207 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3208 | MockRead(SYNCHRONOUS, "hello"), |
| 3209 | }; |
| 3210 | |
| 3211 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3212 | data_writes1, arraysize(data_writes1)); |
| 3213 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3214 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3215 | data_writes2, arraysize(data_writes2)); |
| 3216 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3217 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3218 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3219 | |
| 3220 | TestCompletionCallback callback1; |
| 3221 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3222 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3223 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3224 | |
| 3225 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3226 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3227 | |
| 3228 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3229 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3230 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3231 | log.GetEntries(&entries); |
| 3232 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3233 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3234 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3235 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3236 | entries, pos, |
| 3237 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3238 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3239 | |
| 3240 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3241 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3242 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3243 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3244 | EXPECT_EQ(407, response->headers->response_code()); |
| 3245 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3246 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3247 | |
| 3248 | LoadTimingInfo load_timing_info; |
| 3249 | // CONNECT requests and responses are handled at the connect job level, so |
| 3250 | // the transaction does not yet have a connection. |
| 3251 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3252 | |
| 3253 | TestCompletionCallback callback2; |
| 3254 | |
| 3255 | rv = |
| 3256 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3257 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3258 | |
| 3259 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3260 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3261 | |
| 3262 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3263 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3264 | |
| 3265 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3266 | EXPECT_EQ(200, response->headers->response_code()); |
| 3267 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3268 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3269 | |
| 3270 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3271 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3272 | |
| 3273 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3274 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3275 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3276 | |
| 3277 | trans.reset(); |
| 3278 | session->CloseAllConnections(); |
| 3279 | } |
| 3280 | |
| 3281 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3282 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3283 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3284 | HttpRequestInfo request; |
| 3285 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3286 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3287 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3288 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3289 | request.traffic_annotation = |
| 3290 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3291 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3292 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3293 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3294 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3295 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3296 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3297 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3298 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3299 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3300 | // Since we have proxy, should try to establish tunnel. |
| 3301 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3302 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3303 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3304 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3305 | }; |
| 3306 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3307 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3308 | // connection. |
| 3309 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3310 | // No credentials. |
| 3311 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3312 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3313 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3314 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3315 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3316 | MockWrite data_writes2[] = { |
| 3317 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3318 | // be issuing -- the final header line contains the credentials. |
| 3319 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3320 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3321 | "Proxy-Connection: keep-alive\r\n" |
| 3322 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3323 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3324 | MockWrite("GET / HTTP/1.1\r\n" |
| 3325 | "Host: www.example.org\r\n" |
| 3326 | "Connection: keep-alive\r\n\r\n"), |
| 3327 | }; |
| 3328 | |
| 3329 | MockRead data_reads2[] = { |
| 3330 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3331 | |
| 3332 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3333 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3334 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3335 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3336 | }; |
| 3337 | |
| 3338 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3339 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3340 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3341 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3342 | data_writes2, arraysize(data_writes2)); |
| 3343 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3344 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3345 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3347 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3348 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3349 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3350 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3352 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3353 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3354 | |
| 3355 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3356 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3357 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3358 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3359 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3360 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3361 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3362 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3363 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3364 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3365 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3366 | |
| 3367 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3368 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3369 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3370 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3371 | EXPECT_EQ(407, response->headers->response_code()); |
| 3372 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3373 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3374 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3375 | LoadTimingInfo load_timing_info; |
| 3376 | // CONNECT requests and responses are handled at the connect job level, so |
| 3377 | // the transaction does not yet have a connection. |
| 3378 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3379 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3380 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3381 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3382 | rv = trans->RestartWithAuth( |
| 3383 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3384 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3385 | |
| 3386 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3387 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3388 | |
| 3389 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3390 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3391 | |
| 3392 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3393 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3394 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3395 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3396 | |
| 3397 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3398 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3399 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3400 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3401 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3402 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3403 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3404 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3405 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3406 | } |
| 3407 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3408 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3409 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3410 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3411 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3412 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3413 | // reused. See http://crbug.com/544255. |
| 3414 | for (int i = 0; i < 2; ++i) { |
| 3415 | HttpRequestInfo request; |
| 3416 | request.method = "GET"; |
| 3417 | request.url = GURL("https://www.example.org/"); |
| 3418 | // Ensure that proxy authentication is attempted even |
| 3419 | // when the no authentication data flag is set. |
| 3420 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3421 | request.traffic_annotation = |
| 3422 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3423 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3424 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3425 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3426 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3427 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3428 | BoundTestNetLog log; |
| 3429 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3431 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3432 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3433 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3434 | // Since we have proxy, should try to establish tunnel. |
| 3435 | MockWrite data_writes1[] = { |
| 3436 | MockWrite(ASYNC, 0, |
| 3437 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3438 | "Host: www.example.org:443\r\n" |
| 3439 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3440 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3441 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3442 | // be issuing -- the final header line contains the credentials. |
| 3443 | MockWrite(ASYNC, 3, |
| 3444 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3445 | "Host: www.example.org:443\r\n" |
| 3446 | "Proxy-Connection: keep-alive\r\n" |
| 3447 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3448 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3449 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3450 | // The proxy responds to the connect with a 407, using a persistent |
| 3451 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3452 | MockRead data_reads1[] = { |
| 3453 | // No credentials. |
| 3454 | MockRead(ASYNC, 1, |
| 3455 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3456 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3457 | "Proxy-Connection: keep-alive\r\n" |
| 3458 | "Content-Length: 10\r\n\r\n"), |
| 3459 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3460 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3461 | // Wrong credentials (wrong password). |
| 3462 | MockRead(ASYNC, 4, |
| 3463 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3464 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3465 | "Proxy-Connection: keep-alive\r\n" |
| 3466 | "Content-Length: 10\r\n\r\n"), |
| 3467 | // No response body because the test stops reading here. |
| 3468 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3469 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3470 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3471 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3472 | arraysize(data_writes1)); |
| 3473 | data1.set_busy_before_sync_reads(true); |
| 3474 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3475 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3476 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3478 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3479 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3480 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3481 | TestNetLogEntry::List entries; |
| 3482 | log.GetEntries(&entries); |
| 3483 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3484 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3485 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3486 | ExpectLogContainsSomewhere( |
| 3487 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3488 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3489 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3490 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3491 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3492 | ASSERT_TRUE(response); |
| 3493 | ASSERT_TRUE(response->headers); |
| 3494 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3495 | EXPECT_EQ(407, response->headers->response_code()); |
| 3496 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3497 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3498 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3499 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3500 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3501 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3502 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3503 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3504 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3505 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3506 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3507 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3508 | ASSERT_TRUE(response); |
| 3509 | ASSERT_TRUE(response->headers); |
| 3510 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3511 | EXPECT_EQ(407, response->headers->response_code()); |
| 3512 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3513 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3514 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3515 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3516 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3517 | // out of scope. |
| 3518 | session->CloseAllConnections(); |
| 3519 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3523 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3524 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3525 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3526 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3527 | // reused. See http://crbug.com/544255. |
| 3528 | for (int i = 0; i < 2; ++i) { |
| 3529 | HttpRequestInfo request; |
| 3530 | request.method = "GET"; |
| 3531 | request.url = GURL("https://www.example.org/"); |
| 3532 | // Ensure that proxy authentication is attempted even |
| 3533 | // when the no authentication data flag is set. |
| 3534 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3535 | request.traffic_annotation = |
| 3536 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3537 | |
| 3538 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3539 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3540 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3541 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3542 | BoundTestNetLog log; |
| 3543 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3544 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3545 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3546 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3547 | |
| 3548 | // Since we have proxy, should try to establish tunnel. |
| 3549 | MockWrite data_writes1[] = { |
| 3550 | MockWrite(ASYNC, 0, |
| 3551 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3552 | "Host: www.example.org:443\r\n" |
| 3553 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3555 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3556 | // be issuing -- the final header line contains the credentials. |
| 3557 | MockWrite(ASYNC, 3, |
| 3558 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3559 | "Host: www.example.org:443\r\n" |
| 3560 | "Proxy-Connection: keep-alive\r\n" |
| 3561 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3562 | }; |
| 3563 | |
| 3564 | // The proxy responds to the connect with a 407, using a persistent |
| 3565 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3566 | MockRead data_reads1[] = { |
| 3567 | // No credentials. |
| 3568 | MockRead(ASYNC, 1, |
| 3569 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3570 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3571 | "Content-Length: 10\r\n\r\n"), |
| 3572 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3573 | |
| 3574 | // Wrong credentials (wrong password). |
| 3575 | MockRead(ASYNC, 4, |
| 3576 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3577 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3578 | "Content-Length: 10\r\n\r\n"), |
| 3579 | // No response body because the test stops reading here. |
| 3580 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3581 | }; |
| 3582 | |
| 3583 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3584 | arraysize(data_writes1)); |
| 3585 | data1.set_busy_before_sync_reads(true); |
| 3586 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3587 | |
| 3588 | TestCompletionCallback callback1; |
| 3589 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3590 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3591 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3592 | |
| 3593 | TestNetLogEntry::List entries; |
| 3594 | log.GetEntries(&entries); |
| 3595 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3596 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3597 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3598 | ExpectLogContainsSomewhere( |
| 3599 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3600 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3601 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3603 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3604 | ASSERT_TRUE(response); |
| 3605 | ASSERT_TRUE(response->headers); |
| 3606 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3607 | EXPECT_EQ(407, response->headers->response_code()); |
| 3608 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3609 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3610 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3611 | |
| 3612 | TestCompletionCallback callback2; |
| 3613 | |
| 3614 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3615 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3616 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3617 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3618 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3619 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3620 | ASSERT_TRUE(response); |
| 3621 | ASSERT_TRUE(response->headers); |
| 3622 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3623 | EXPECT_EQ(407, response->headers->response_code()); |
| 3624 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3625 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3626 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3627 | |
| 3628 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3629 | // out of scope. |
| 3630 | session->CloseAllConnections(); |
| 3631 | } |
| 3632 | } |
| 3633 | |
| 3634 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3635 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3636 | // the case the server sends extra data on the original socket, so it can't be |
| 3637 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3638 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3639 | HttpRequestInfo request; |
| 3640 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3641 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3642 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3643 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3644 | request.traffic_annotation = |
| 3645 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3646 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3647 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3648 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3649 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3650 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3651 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3652 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3653 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3654 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3655 | // Since we have proxy, should try to establish tunnel. |
| 3656 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3657 | MockWrite(ASYNC, 0, |
| 3658 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3659 | "Host: www.example.org:443\r\n" |
| 3660 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3661 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3662 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3663 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3664 | // extra data, so the socket cannot be reused. |
| 3665 | MockRead data_reads1[] = { |
| 3666 | // No credentials. |
| 3667 | MockRead(ASYNC, 1, |
| 3668 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3669 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3670 | "Content-Length: 10\r\n\r\n"), |
| 3671 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3672 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3673 | }; |
| 3674 | |
| 3675 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3676 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3677 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3678 | MockWrite(ASYNC, 0, |
| 3679 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3680 | "Host: www.example.org:443\r\n" |
| 3681 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3682 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3683 | |
| 3684 | MockWrite(ASYNC, 2, |
| 3685 | "GET / HTTP/1.1\r\n" |
| 3686 | "Host: www.example.org\r\n" |
| 3687 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3688 | }; |
| 3689 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3690 | MockRead data_reads2[] = { |
| 3691 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3692 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3693 | MockRead(ASYNC, 3, |
| 3694 | "HTTP/1.1 200 OK\r\n" |
| 3695 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3696 | "Content-Length: 5\r\n\r\n"), |
| 3697 | // No response body because the test stops reading here. |
| 3698 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3699 | }; |
| 3700 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3701 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3702 | arraysize(data_writes1)); |
| 3703 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3704 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3705 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3706 | arraysize(data_writes2)); |
| 3707 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3708 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3709 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3710 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3711 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3712 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3713 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3714 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3715 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3716 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3717 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3718 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3719 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3720 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3721 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3722 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3723 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3724 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3725 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3726 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3727 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3728 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3729 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3730 | ASSERT_TRUE(response); |
| 3731 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3732 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3733 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3734 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3735 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3736 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3737 | LoadTimingInfo load_timing_info; |
| 3738 | // CONNECT requests and responses are handled at the connect job level, so |
| 3739 | // the transaction does not yet have a connection. |
| 3740 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3741 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3742 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3743 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3744 | rv = |
| 3745 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3746 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3747 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3748 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3749 | EXPECT_EQ(200, response->headers->response_code()); |
| 3750 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3751 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3752 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3753 | // The password prompt info should not be set. |
| 3754 | EXPECT_FALSE(response->auth_challenge); |
| 3755 | |
| 3756 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3757 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3758 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3759 | |
| 3760 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3761 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3762 | } |
| 3763 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3764 | // Test the case a proxy closes a socket while the challenge body is being |
| 3765 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3766 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3767 | HttpRequestInfo request; |
| 3768 | request.method = "GET"; |
| 3769 | request.url = GURL("https://www.example.org/"); |
| 3770 | // Ensure that proxy authentication is attempted even |
| 3771 | // when the no authentication data flag is set. |
| 3772 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3773 | request.traffic_annotation = |
| 3774 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3775 | |
| 3776 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3777 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3778 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3779 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3780 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3781 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3782 | |
| 3783 | // Since we have proxy, should try to establish tunnel. |
| 3784 | MockWrite data_writes1[] = { |
| 3785 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3786 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3787 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3788 | }; |
| 3789 | |
| 3790 | // The proxy responds to the connect with a 407, using a persistent |
| 3791 | // connection. |
| 3792 | MockRead data_reads1[] = { |
| 3793 | // No credentials. |
| 3794 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3795 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3796 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3797 | // Server hands up in the middle of the body. |
| 3798 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3799 | }; |
| 3800 | |
| 3801 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3802 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3803 | // be issuing -- the final header line contains the credentials. |
| 3804 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3805 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3806 | "Proxy-Connection: keep-alive\r\n" |
| 3807 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3808 | |
| 3809 | MockWrite("GET / HTTP/1.1\r\n" |
| 3810 | "Host: www.example.org\r\n" |
| 3811 | "Connection: keep-alive\r\n\r\n"), |
| 3812 | }; |
| 3813 | |
| 3814 | MockRead data_reads2[] = { |
| 3815 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3816 | |
| 3817 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3818 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3819 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3820 | MockRead(SYNCHRONOUS, "hello"), |
| 3821 | }; |
| 3822 | |
| 3823 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3824 | data_writes1, arraysize(data_writes1)); |
| 3825 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3826 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3827 | data_writes2, arraysize(data_writes2)); |
| 3828 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3829 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3830 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3831 | |
| 3832 | TestCompletionCallback callback; |
| 3833 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3834 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3835 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3837 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3838 | ASSERT_TRUE(response); |
| 3839 | ASSERT_TRUE(response->headers); |
| 3840 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3841 | EXPECT_EQ(407, response->headers->response_code()); |
| 3842 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3843 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3844 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3845 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3846 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3847 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3848 | ASSERT_TRUE(response); |
| 3849 | ASSERT_TRUE(response->headers); |
| 3850 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3851 | EXPECT_EQ(200, response->headers->response_code()); |
| 3852 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3853 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3854 | EXPECT_EQ("hello", body); |
| 3855 | } |
| 3856 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3857 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3858 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3859 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3860 | HttpRequestInfo request; |
| 3861 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3862 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3863 | request.traffic_annotation = |
| 3864 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3865 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3866 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3867 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3868 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3869 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3870 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3871 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3872 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3873 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3874 | // Since we have proxy, should try to establish tunnel. |
| 3875 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3876 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3877 | "Host: www.example.org:443\r\n" |
| 3878 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3879 | }; |
| 3880 | |
| 3881 | // The proxy responds to the connect with a 407. |
| 3882 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3883 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3884 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3885 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3886 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3887 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3888 | }; |
| 3889 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3890 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3891 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3892 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3893 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3894 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3895 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3896 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3898 | |
| 3899 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3900 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3901 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3902 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3903 | ASSERT_TRUE(response); |
| 3904 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3905 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3906 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3907 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3908 | |
| 3909 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3910 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3911 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3912 | |
| 3913 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3914 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3915 | } |
| 3916 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3917 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3918 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3919 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3920 | HttpRequestInfo request; |
| 3921 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3922 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3923 | request.traffic_annotation = |
| 3924 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3925 | |
| 3926 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3927 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3928 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3929 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3930 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3931 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3932 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3933 | |
| 3934 | // Since we have proxy, should try to establish tunnel. |
| 3935 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3936 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3937 | "Host: www.example.org:443\r\n" |
| 3938 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3939 | }; |
| 3940 | |
| 3941 | // The proxy responds to the connect with a 407. |
| 3942 | MockRead data_reads[] = { |
| 3943 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3944 | MockRead("X-Foo: bar\r\n"), |
| 3945 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3946 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3947 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3948 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3949 | }; |
| 3950 | |
| 3951 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3952 | arraysize(data_writes)); |
| 3953 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3954 | |
| 3955 | TestCompletionCallback callback; |
| 3956 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3957 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3958 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3959 | |
| 3960 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3961 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3962 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3963 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3964 | ASSERT_TRUE(response); |
| 3965 | ASSERT_TRUE(response->headers); |
| 3966 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3967 | EXPECT_EQ(407, response->headers->response_code()); |
| 3968 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3969 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3970 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3971 | |
| 3972 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3973 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3974 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3975 | |
| 3976 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3977 | session->CloseAllConnections(); |
| 3978 | } |
| 3979 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3980 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3981 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3982 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3983 | HttpRequestInfo request; |
| 3984 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3985 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3986 | request.traffic_annotation = |
| 3987 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3988 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3989 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3990 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3991 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3992 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3993 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3994 | MockWrite( |
| 3995 | "GET / HTTP/1.1\r\n" |
| 3996 | "Host: www.example.org\r\n" |
| 3997 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3998 | }; |
| 3999 | |
| 4000 | MockRead data_reads1[] = { |
| 4001 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4002 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4003 | // Large content-length -- won't matter, as connection will be reset. |
| 4004 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4005 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4006 | }; |
| 4007 | |
| 4008 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4009 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4010 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4011 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4012 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4013 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4014 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4015 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4016 | |
| 4017 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4018 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4019 | } |
| 4020 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4021 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4022 | // through a non-authenticating proxy. The request should fail with |
| 4023 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4024 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4025 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4026 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4027 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4028 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4029 | HttpRequestInfo request; |
| 4030 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4031 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4032 | request.traffic_annotation = |
| 4033 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4034 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4035 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4036 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4037 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4038 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4040 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4041 | // Since we have proxy, should try to establish tunnel. |
| 4042 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4043 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4044 | "Host: www.example.org:443\r\n" |
| 4045 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4046 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4047 | MockWrite("GET / HTTP/1.1\r\n" |
| 4048 | "Host: www.example.org\r\n" |
| 4049 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4050 | }; |
| 4051 | |
| 4052 | MockRead data_reads1[] = { |
| 4053 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4054 | |
| 4055 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4056 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4057 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4058 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4059 | }; |
| 4060 | |
| 4061 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4062 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4063 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4064 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4065 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4066 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4067 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4068 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4069 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4070 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4071 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4072 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4073 | |
| 4074 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4075 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4076 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4077 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4078 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4079 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4080 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4081 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4082 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4083 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4084 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4085 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4086 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4087 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4088 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4089 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4090 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4091 | HttpRequestInfo request; |
| 4092 | request.method = "GET"; |
| 4093 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4094 | request.traffic_annotation = |
| 4095 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4096 | |
| 4097 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4098 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4099 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4100 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4101 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4102 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4103 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4104 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4105 | mock_handler->set_allows_default_credentials(true); |
| 4106 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4107 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4108 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4109 | |
| 4110 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4111 | NetLog net_log; |
| 4112 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4113 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4114 | |
| 4115 | // Since we have proxy, should try to establish tunnel. |
| 4116 | MockWrite data_writes1[] = { |
| 4117 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4118 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4119 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4120 | }; |
| 4121 | |
| 4122 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4123 | // connection. |
| 4124 | MockRead data_reads1[] = { |
| 4125 | // No credentials. |
| 4126 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4127 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4128 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4129 | }; |
| 4130 | |
| 4131 | // Since the first connection couldn't be reused, need to establish another |
| 4132 | // once given credentials. |
| 4133 | MockWrite data_writes2[] = { |
| 4134 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4135 | // be issuing -- the final header line contains the credentials. |
| 4136 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4137 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4138 | "Proxy-Connection: keep-alive\r\n" |
| 4139 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4140 | |
| 4141 | MockWrite("GET / HTTP/1.1\r\n" |
| 4142 | "Host: www.example.org\r\n" |
| 4143 | "Connection: keep-alive\r\n\r\n"), |
| 4144 | }; |
| 4145 | |
| 4146 | MockRead data_reads2[] = { |
| 4147 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4148 | |
| 4149 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4150 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4151 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4152 | MockRead(SYNCHRONOUS, "hello"), |
| 4153 | }; |
| 4154 | |
| 4155 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4156 | data_writes1, arraysize(data_writes1)); |
| 4157 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4158 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4159 | data_writes2, arraysize(data_writes2)); |
| 4160 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4161 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4162 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4163 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4164 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4165 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4166 | |
| 4167 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4168 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4169 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4170 | |
| 4171 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4172 | ASSERT_TRUE(response); |
| 4173 | ASSERT_TRUE(response->headers); |
| 4174 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4175 | EXPECT_EQ(407, response->headers->response_code()); |
| 4176 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4177 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4178 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4179 | |
| 4180 | LoadTimingInfo load_timing_info; |
| 4181 | // CONNECT requests and responses are handled at the connect job level, so |
| 4182 | // the transaction does not yet have a connection. |
| 4183 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4184 | |
| 4185 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4186 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4187 | response = trans->GetResponseInfo(); |
| 4188 | ASSERT_TRUE(response); |
| 4189 | ASSERT_TRUE(response->headers); |
| 4190 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4191 | EXPECT_EQ(200, response->headers->response_code()); |
| 4192 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4193 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4194 | |
| 4195 | // The password prompt info should not be set. |
| 4196 | EXPECT_FALSE(response->auth_challenge); |
| 4197 | |
| 4198 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4199 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4200 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4201 | |
| 4202 | trans.reset(); |
| 4203 | session->CloseAllConnections(); |
| 4204 | } |
| 4205 | |
| 4206 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4207 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4208 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4209 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4210 | HttpRequestInfo request; |
| 4211 | request.method = "GET"; |
| 4212 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4213 | request.traffic_annotation = |
| 4214 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4215 | |
| 4216 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4217 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4218 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4219 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4220 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4221 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4222 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4223 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4224 | mock_handler->set_allows_default_credentials(true); |
| 4225 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4226 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4227 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4228 | |
| 4229 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4230 | NetLog net_log; |
| 4231 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4232 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4233 | |
| 4234 | // Should try to establish tunnel. |
| 4235 | MockWrite data_writes1[] = { |
| 4236 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4237 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4238 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4239 | |
| 4240 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4241 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4242 | "Proxy-Connection: keep-alive\r\n" |
| 4243 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4244 | }; |
| 4245 | |
| 4246 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4247 | // connection. |
| 4248 | MockRead data_reads1[] = { |
| 4249 | // No credentials. |
| 4250 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4251 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4252 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4253 | }; |
| 4254 | |
| 4255 | // Since the first connection was closed, need to establish another once given |
| 4256 | // credentials. |
| 4257 | MockWrite data_writes2[] = { |
| 4258 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4259 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4260 | "Proxy-Connection: keep-alive\r\n" |
| 4261 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4262 | |
| 4263 | MockWrite("GET / HTTP/1.1\r\n" |
| 4264 | "Host: www.example.org\r\n" |
| 4265 | "Connection: keep-alive\r\n\r\n"), |
| 4266 | }; |
| 4267 | |
| 4268 | MockRead data_reads2[] = { |
| 4269 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4270 | |
| 4271 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4272 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4273 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4274 | MockRead(SYNCHRONOUS, "hello"), |
| 4275 | }; |
| 4276 | |
| 4277 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4278 | data_writes1, arraysize(data_writes1)); |
| 4279 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4280 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4281 | data_writes2, arraysize(data_writes2)); |
| 4282 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4283 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4284 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4285 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4286 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4287 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4288 | |
| 4289 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4290 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4291 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4292 | |
| 4293 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4294 | ASSERT_TRUE(response); |
| 4295 | ASSERT_TRUE(response->headers); |
| 4296 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4297 | EXPECT_EQ(407, response->headers->response_code()); |
| 4298 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4299 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4300 | EXPECT_FALSE(response->auth_challenge); |
| 4301 | |
| 4302 | LoadTimingInfo load_timing_info; |
| 4303 | // CONNECT requests and responses are handled at the connect job level, so |
| 4304 | // the transaction does not yet have a connection. |
| 4305 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4306 | |
| 4307 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4308 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4309 | |
| 4310 | response = trans->GetResponseInfo(); |
| 4311 | ASSERT_TRUE(response); |
| 4312 | ASSERT_TRUE(response->headers); |
| 4313 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4314 | EXPECT_EQ(200, response->headers->response_code()); |
| 4315 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4316 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4317 | |
| 4318 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4319 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4320 | |
| 4321 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4322 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4323 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4324 | |
| 4325 | trans.reset(); |
| 4326 | session->CloseAllConnections(); |
| 4327 | } |
| 4328 | |
| 4329 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4330 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4331 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4332 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4333 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4334 | HttpRequestInfo request; |
| 4335 | request.method = "GET"; |
| 4336 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4337 | request.traffic_annotation = |
| 4338 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4339 | |
| 4340 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4341 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4342 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4343 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4344 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4345 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4346 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4347 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4348 | mock_handler->set_allows_default_credentials(true); |
| 4349 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4350 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4351 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4352 | |
| 4353 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4354 | NetLog net_log; |
| 4355 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4356 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4357 | |
| 4358 | // Should try to establish tunnel. |
| 4359 | MockWrite data_writes1[] = { |
| 4360 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4361 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4362 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4363 | |
| 4364 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4365 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4366 | "Proxy-Connection: keep-alive\r\n" |
| 4367 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4368 | }; |
| 4369 | |
| 4370 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4371 | // second request is sent. |
| 4372 | MockRead data_reads1[] = { |
| 4373 | // No credentials. |
| 4374 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4375 | MockRead("Content-Length: 0\r\n"), |
| 4376 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4377 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4378 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4379 | }; |
| 4380 | |
| 4381 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4382 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4383 | // request. |
| 4384 | MockWrite data_writes2[] = { |
| 4385 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4386 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4387 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4388 | }; |
| 4389 | |
| 4390 | // The proxy, having had more than enough of us, just hangs up. |
| 4391 | MockRead data_reads2[] = { |
| 4392 | // No credentials. |
| 4393 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4394 | }; |
| 4395 | |
| 4396 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4397 | data_writes1, arraysize(data_writes1)); |
| 4398 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4399 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4400 | data_writes2, arraysize(data_writes2)); |
| 4401 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4402 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4403 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4404 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4405 | |
| 4406 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4407 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4408 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4409 | |
| 4410 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4411 | ASSERT_TRUE(response); |
| 4412 | ASSERT_TRUE(response->headers); |
| 4413 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4414 | EXPECT_EQ(407, response->headers->response_code()); |
| 4415 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4416 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4417 | EXPECT_FALSE(response->auth_challenge); |
| 4418 | |
| 4419 | LoadTimingInfo load_timing_info; |
| 4420 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4421 | |
| 4422 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4423 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4424 | |
| 4425 | trans.reset(); |
| 4426 | session->CloseAllConnections(); |
| 4427 | } |
| 4428 | |
| 4429 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4430 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4431 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4432 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4433 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4434 | HttpRequestInfo request; |
| 4435 | request.method = "GET"; |
| 4436 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4437 | request.traffic_annotation = |
| 4438 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4439 | |
| 4440 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4441 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4442 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4443 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4444 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4445 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4446 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4447 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4448 | mock_handler->set_allows_default_credentials(true); |
| 4449 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4450 | HttpAuth::AUTH_PROXY); |
| 4451 | // Add another handler for the second challenge. It supports default |
| 4452 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4453 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4454 | mock_handler->set_allows_default_credentials(true); |
| 4455 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4456 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4457 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4458 | |
| 4459 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4460 | NetLog net_log; |
| 4461 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4462 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4463 | |
| 4464 | // Should try to establish tunnel. |
| 4465 | MockWrite data_writes1[] = { |
| 4466 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4467 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4468 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4469 | }; |
| 4470 | |
| 4471 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4472 | // connection. |
| 4473 | MockRead data_reads1[] = { |
| 4474 | // No credentials. |
| 4475 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4476 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4477 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4478 | }; |
| 4479 | |
| 4480 | // Since the first connection was closed, need to establish another once given |
| 4481 | // credentials. |
| 4482 | MockWrite data_writes2[] = { |
| 4483 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4484 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4485 | "Proxy-Connection: keep-alive\r\n" |
| 4486 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4487 | }; |
| 4488 | |
| 4489 | MockRead data_reads2[] = { |
| 4490 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4491 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4492 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4493 | }; |
| 4494 | |
| 4495 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4496 | data_writes1, arraysize(data_writes1)); |
| 4497 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4498 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4499 | data_writes2, arraysize(data_writes2)); |
| 4500 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4501 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4503 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4504 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4505 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4506 | |
| 4507 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4508 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4509 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4510 | |
| 4511 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4512 | ASSERT_TRUE(response); |
| 4513 | ASSERT_TRUE(response->headers); |
| 4514 | EXPECT_EQ(407, response->headers->response_code()); |
| 4515 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4516 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4517 | EXPECT_FALSE(response->auth_challenge); |
| 4518 | |
| 4519 | LoadTimingInfo load_timing_info; |
| 4520 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4521 | |
| 4522 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4523 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4524 | response = trans->GetResponseInfo(); |
| 4525 | ASSERT_TRUE(response); |
| 4526 | ASSERT_TRUE(response->headers); |
| 4527 | EXPECT_EQ(407, response->headers->response_code()); |
| 4528 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4529 | EXPECT_TRUE(response->auth_challenge); |
| 4530 | |
| 4531 | trans.reset(); |
| 4532 | session->CloseAllConnections(); |
| 4533 | } |
| 4534 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4535 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4536 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4537 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4538 | // authentication handshake can continue with the same scheme but with a |
| 4539 | // different identity. |
| 4540 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4541 | HttpRequestInfo request; |
| 4542 | request.method = "GET"; |
| 4543 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4544 | request.traffic_annotation = |
| 4545 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4546 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4547 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4548 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4549 | |
| 4550 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4551 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4552 | mock_handler->set_allows_default_credentials(true); |
| 4553 | mock_handler->set_allows_explicit_credentials(true); |
| 4554 | mock_handler->set_connection_based(true); |
| 4555 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4556 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4557 | HttpAuth::AUTH_SERVER); |
| 4558 | |
| 4559 | // Add another handler for the second challenge. It supports default |
| 4560 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4561 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4562 | mock_handler->set_allows_default_credentials(true); |
| 4563 | mock_handler->set_allows_explicit_credentials(true); |
| 4564 | mock_handler->set_connection_based(true); |
| 4565 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4566 | HttpAuth::AUTH_SERVER); |
| 4567 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4568 | |
| 4569 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4570 | |
| 4571 | MockWrite data_writes1[] = { |
| 4572 | MockWrite("GET / HTTP/1.1\r\n" |
| 4573 | "Host: www.example.org\r\n" |
| 4574 | "Connection: keep-alive\r\n\r\n"), |
| 4575 | }; |
| 4576 | |
| 4577 | MockRead data_reads1[] = { |
| 4578 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4579 | "WWW-Authenticate: Mock\r\n" |
| 4580 | "Connection: keep-alive\r\n\r\n"), |
| 4581 | }; |
| 4582 | |
| 4583 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4584 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4585 | // transaction procceds without an authorization header. |
| 4586 | MockWrite data_writes2[] = { |
| 4587 | MockWrite("GET / HTTP/1.1\r\n" |
| 4588 | "Host: www.example.org\r\n" |
| 4589 | "Connection: keep-alive\r\n\r\n"), |
| 4590 | }; |
| 4591 | |
| 4592 | MockRead data_reads2[] = { |
| 4593 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4594 | "WWW-Authenticate: Mock\r\n" |
| 4595 | "Connection: keep-alive\r\n\r\n"), |
| 4596 | }; |
| 4597 | |
| 4598 | MockWrite data_writes3[] = { |
| 4599 | MockWrite("GET / HTTP/1.1\r\n" |
| 4600 | "Host: www.example.org\r\n" |
| 4601 | "Connection: keep-alive\r\n" |
| 4602 | "Authorization: auth_token\r\n\r\n"), |
| 4603 | }; |
| 4604 | |
| 4605 | MockRead data_reads3[] = { |
| 4606 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4607 | "Content-Length: 5\r\n" |
| 4608 | "Content-Type: text/plain\r\n" |
| 4609 | "Connection: keep-alive\r\n\r\n" |
| 4610 | "Hello"), |
| 4611 | }; |
| 4612 | |
| 4613 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4614 | data_writes1, arraysize(data_writes1)); |
| 4615 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4616 | |
| 4617 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4618 | data_writes2, arraysize(data_writes2)); |
| 4619 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4620 | |
| 4621 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4622 | data_writes3, arraysize(data_writes3)); |
| 4623 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4624 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4625 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4626 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4627 | |
| 4628 | TestCompletionCallback callback; |
| 4629 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4630 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4631 | |
| 4632 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4633 | ASSERT_TRUE(response); |
| 4634 | ASSERT_TRUE(response->headers); |
| 4635 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4636 | |
| 4637 | // The following three tests assert that an authentication challenge was |
| 4638 | // received and that the stack is ready to respond to the challenge using |
| 4639 | // ambient credentials. |
| 4640 | EXPECT_EQ(401, response->headers->response_code()); |
| 4641 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4642 | EXPECT_FALSE(response->auth_challenge); |
| 4643 | |
| 4644 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4645 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4646 | response = trans->GetResponseInfo(); |
| 4647 | ASSERT_TRUE(response); |
| 4648 | ASSERT_TRUE(response->headers); |
| 4649 | |
| 4650 | // The following three tests assert that an authentication challenge was |
| 4651 | // received and that the stack needs explicit credentials before it is ready |
| 4652 | // to respond to the challenge. |
| 4653 | EXPECT_EQ(401, response->headers->response_code()); |
| 4654 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4655 | EXPECT_TRUE(response->auth_challenge); |
| 4656 | |
| 4657 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4658 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4659 | response = trans->GetResponseInfo(); |
| 4660 | ASSERT_TRUE(response); |
| 4661 | ASSERT_TRUE(response->headers); |
| 4662 | EXPECT_EQ(200, response->headers->response_code()); |
| 4663 | |
| 4664 | trans.reset(); |
| 4665 | session->CloseAllConnections(); |
| 4666 | } |
| 4667 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4668 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4669 | // schemes, based on the path of the URL being requests. |
| 4670 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4671 | public: |
| 4672 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4673 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4674 | |
| 4675 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4676 | |
| 4677 | static HostPortPair ProxyHostPortPair() { |
| 4678 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4679 | } |
| 4680 | |
| 4681 | // ProxyResolver implementation. |
| 4682 | int GetProxyForURL(const GURL& url, |
| 4683 | ProxyInfo* results, |
| 4684 | const CompletionCallback& callback, |
| 4685 | std::unique_ptr<Request>* request, |
| 4686 | const NetLogWithSource& /*net_log*/) override { |
| 4687 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4688 | results->set_traffic_annotation( |
| 4689 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4690 | if (url.path() == "/socks4") { |
| 4691 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4692 | return OK; |
| 4693 | } |
| 4694 | if (url.path() == "/socks5") { |
| 4695 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4696 | return OK; |
| 4697 | } |
| 4698 | if (url.path() == "/http") { |
| 4699 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4700 | return OK; |
| 4701 | } |
| 4702 | if (url.path() == "/https") { |
| 4703 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4704 | return OK; |
| 4705 | } |
| 4706 | NOTREACHED(); |
| 4707 | return ERR_NOT_IMPLEMENTED; |
| 4708 | } |
| 4709 | |
| 4710 | private: |
| 4711 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4712 | }; |
| 4713 | |
| 4714 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4715 | : public ProxyResolverFactory { |
| 4716 | public: |
| 4717 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4718 | : ProxyResolverFactory(false) {} |
| 4719 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4720 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4721 | std::unique_ptr<ProxyResolver>* resolver, |
| 4722 | const CompletionCallback& callback, |
| 4723 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4724 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4725 | return OK; |
| 4726 | } |
| 4727 | |
| 4728 | private: |
| 4729 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4730 | }; |
| 4731 | |
| 4732 | // Check that when different proxy schemes are all applied to a proxy at the |
| 4733 | // same address, the sonnections are not grouped together. i.e., a request to |
| 4734 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4735 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4736 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4737 | session_deps_.proxy_resolution_service = |
| 4738 | std::make_unique<ProxyResolutionService>( |
| 4739 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4740 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4741 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4742 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4743 | |
| 4744 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4745 | |
| 4746 | MockWrite socks_writes[] = { |
| 4747 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4748 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4749 | MockWrite(SYNCHRONOUS, |
| 4750 | "GET /socks4 HTTP/1.1\r\n" |
| 4751 | "Host: test\r\n" |
| 4752 | "Connection: keep-alive\r\n\r\n"), |
| 4753 | }; |
| 4754 | MockRead socks_reads[] = { |
| 4755 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4756 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4757 | "Connection: keep-alive\r\n" |
| 4758 | "Content-Length: 15\r\n\r\n" |
| 4759 | "SOCKS4 Response"), |
| 4760 | }; |
| 4761 | StaticSocketDataProvider socks_data(socks_reads, arraysize(socks_reads), |
| 4762 | socks_writes, arraysize(socks_writes)); |
| 4763 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4764 | |
| 4765 | const char kSOCKS5Request[] = { |
| 4766 | 0x05, // Version |
| 4767 | 0x01, // Command (CONNECT) |
| 4768 | 0x00, // Reserved |
| 4769 | 0x03, // Address type (DOMAINNAME) |
| 4770 | 0x04, // Length of domain (4) |
| 4771 | 't', 'e', 's', 't', // Domain string |
| 4772 | 0x00, 0x50, // 16-bit port (80) |
| 4773 | }; |
| 4774 | MockWrite socks5_writes[] = { |
| 4775 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
| 4776 | MockWrite(ASYNC, kSOCKS5Request, arraysize(kSOCKS5Request)), |
| 4777 | MockWrite(SYNCHRONOUS, |
| 4778 | "GET /socks5 HTTP/1.1\r\n" |
| 4779 | "Host: test\r\n" |
| 4780 | "Connection: keep-alive\r\n\r\n"), |
| 4781 | }; |
| 4782 | MockRead socks5_reads[] = { |
| 4783 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4784 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4785 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4786 | "Connection: keep-alive\r\n" |
| 4787 | "Content-Length: 15\r\n\r\n" |
| 4788 | "SOCKS5 Response"), |
| 4789 | }; |
| 4790 | StaticSocketDataProvider socks5_data(socks5_reads, arraysize(socks5_reads), |
| 4791 | socks5_writes, arraysize(socks5_writes)); |
| 4792 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 4793 | |
| 4794 | MockWrite http_writes[] = { |
| 4795 | MockWrite(SYNCHRONOUS, |
| 4796 | "GET http://test/http HTTP/1.1\r\n" |
| 4797 | "Host: test\r\n" |
| 4798 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4799 | }; |
| 4800 | MockRead http_reads[] = { |
| 4801 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4802 | "Proxy-Connection: keep-alive\r\n" |
| 4803 | "Content-Length: 13\r\n\r\n" |
| 4804 | "HTTP Response"), |
| 4805 | }; |
| 4806 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 4807 | http_writes, arraysize(http_writes)); |
| 4808 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 4809 | |
| 4810 | MockWrite https_writes[] = { |
| 4811 | MockWrite(SYNCHRONOUS, |
| 4812 | "GET http://test/https HTTP/1.1\r\n" |
| 4813 | "Host: test\r\n" |
| 4814 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4815 | }; |
| 4816 | MockRead https_reads[] = { |
| 4817 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4818 | "Proxy-Connection: keep-alive\r\n" |
| 4819 | "Content-Length: 14\r\n\r\n" |
| 4820 | "HTTPS Response"), |
| 4821 | }; |
| 4822 | StaticSocketDataProvider https_data(https_reads, arraysize(https_reads), |
| 4823 | https_writes, arraysize(https_writes)); |
| 4824 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 4825 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 4826 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4827 | |
| 4828 | struct TestCase { |
| 4829 | GURL url; |
| 4830 | std::string expected_response; |
| 4831 | // How many idle sockets there should be in the SOCKS proxy socket pool |
| 4832 | // after the test. |
| 4833 | int expected_idle_socks_sockets; |
| 4834 | // How many idle sockets there should be in the HTTP proxy socket pool after |
| 4835 | // the test. |
| 4836 | int expected_idle_http_sockets; |
| 4837 | } const kTestCases[] = { |
| 4838 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0}, |
| 4839 | {GURL("http://test/socks5"), "SOCKS5 Response", 2, 0}, |
| 4840 | {GURL("http://test/http"), "HTTP Response", 2, 1}, |
| 4841 | {GURL("http://test/https"), "HTTPS Response", 2, 2}, |
| 4842 | }; |
| 4843 | |
| 4844 | for (const auto& test_case : kTestCases) { |
| 4845 | HttpRequestInfo request; |
| 4846 | request.method = "GET"; |
| 4847 | request.url = test_case.url; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4848 | request.traffic_annotation = |
| 4849 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4850 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 4851 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 4852 | session.get()); |
| 4853 | TestCompletionCallback callback; |
| 4854 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4855 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4856 | |
| 4857 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4858 | ASSERT_TRUE(response); |
| 4859 | ASSERT_TRUE(response->headers); |
| 4860 | EXPECT_EQ(200, response->headers->response_code()); |
| 4861 | std::string response_data; |
| 4862 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4863 | EXPECT_EQ(test_case.expected_response, response_data); |
| 4864 | |
| 4865 | // Return the socket to the socket pool, so can make sure it's not used for |
| 4866 | // the next requests. |
| 4867 | trans.reset(); |
| 4868 | base::RunLoop().RunUntilIdle(); |
| 4869 | |
| 4870 | // Check the number of idle sockets in the pool, to make sure that used |
| 4871 | // sockets are indeed being returned to the socket pool. If each request |
| 4872 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 4873 | // pass. |
| 4874 | EXPECT_EQ( |
| 4875 | test_case.expected_idle_socks_sockets, |
| 4876 | session |
| 4877 | ->GetSocketPoolForSOCKSProxy( |
| 4878 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4879 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4880 | ->IdleSocketCount()); |
| 4881 | EXPECT_EQ( |
| 4882 | test_case.expected_idle_http_sockets, |
| 4883 | session |
| 4884 | ->GetSocketPoolForHTTPProxy( |
| 4885 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4886 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4887 | ->IdleSocketCount()); |
| 4888 | } |
| 4889 | } |
| 4890 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4891 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4892 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4893 | HttpRequestInfo request1; |
| 4894 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4895 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4896 | request1.traffic_annotation = |
| 4897 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4898 | |
| 4899 | HttpRequestInfo request2; |
| 4900 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4901 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4902 | request2.traffic_annotation = |
| 4903 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4904 | |
| 4905 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4906 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4907 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4908 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4909 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4910 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4911 | |
| 4912 | // Since we have proxy, should try to establish tunnel. |
| 4913 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4914 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4915 | "Host: www.example.org:443\r\n" |
| 4916 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4917 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4918 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4919 | "Host: www.example.org\r\n" |
| 4920 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4921 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4922 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4923 | "Host: www.example.org\r\n" |
| 4924 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4925 | }; |
| 4926 | |
| 4927 | // The proxy responds to the connect with a 407, using a persistent |
| 4928 | // connection. |
| 4929 | MockRead data_reads1[] = { |
| 4930 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4931 | |
| 4932 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4933 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4934 | MockRead(SYNCHRONOUS, "1"), |
| 4935 | |
| 4936 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4937 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4938 | MockRead(SYNCHRONOUS, "22"), |
| 4939 | }; |
| 4940 | |
| 4941 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4942 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4943 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4944 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4945 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4946 | |
| 4947 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4948 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4949 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4950 | |
| 4951 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4952 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4953 | |
| 4954 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4955 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4956 | |
| 4957 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4958 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4959 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4960 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4961 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4962 | |
| 4963 | LoadTimingInfo load_timing_info1; |
| 4964 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4965 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4966 | |
| 4967 | trans1.reset(); |
| 4968 | |
| 4969 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4970 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4971 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4972 | |
| 4973 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4974 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4975 | |
| 4976 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4977 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4978 | |
| 4979 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4980 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4981 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4982 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4983 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4984 | |
| 4985 | LoadTimingInfo load_timing_info2; |
| 4986 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4987 | TestLoadTimingReused(load_timing_info2); |
| 4988 | |
| 4989 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4990 | |
| 4991 | trans2.reset(); |
| 4992 | session->CloseAllConnections(); |
| 4993 | } |
| 4994 | |
| 4995 | // 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] | 4996 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4997 | HttpRequestInfo request1; |
| 4998 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4999 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5000 | request1.traffic_annotation = |
| 5001 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5002 | |
| 5003 | HttpRequestInfo request2; |
| 5004 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5005 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5006 | request2.traffic_annotation = |
| 5007 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5008 | |
| 5009 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5010 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5011 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5012 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5013 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5014 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5015 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5016 | |
| 5017 | // Since we have proxy, should try to establish tunnel. |
| 5018 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5019 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5020 | "Host: www.example.org:443\r\n" |
| 5021 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5022 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5023 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5024 | "Host: www.example.org\r\n" |
| 5025 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5026 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5027 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5028 | "Host: www.example.org\r\n" |
| 5029 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5030 | }; |
| 5031 | |
| 5032 | // The proxy responds to the connect with a 407, using a persistent |
| 5033 | // connection. |
| 5034 | MockRead data_reads1[] = { |
| 5035 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5036 | |
| 5037 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5038 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5039 | MockRead(SYNCHRONOUS, "1"), |
| 5040 | |
| 5041 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5042 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5043 | MockRead(SYNCHRONOUS, "22"), |
| 5044 | }; |
| 5045 | |
| 5046 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5047 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5048 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5049 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5050 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5051 | |
| 5052 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5053 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5054 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5055 | |
| 5056 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5057 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5058 | |
| 5059 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5060 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5061 | |
| 5062 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5063 | ASSERT_TRUE(response1); |
| 5064 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5065 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5066 | |
| 5067 | LoadTimingInfo load_timing_info1; |
| 5068 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5069 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5070 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5071 | |
| 5072 | trans1.reset(); |
| 5073 | |
| 5074 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5075 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5076 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5077 | |
| 5078 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5080 | |
| 5081 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5082 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5083 | |
| 5084 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5085 | ASSERT_TRUE(response2); |
| 5086 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5087 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5088 | |
| 5089 | LoadTimingInfo load_timing_info2; |
| 5090 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5091 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5092 | |
| 5093 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5094 | |
| 5095 | trans2.reset(); |
| 5096 | session->CloseAllConnections(); |
| 5097 | } |
| 5098 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5099 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5100 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5101 | HttpRequestInfo request; |
| 5102 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5103 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5104 | request.traffic_annotation = |
| 5105 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5106 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5107 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5108 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5109 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5110 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5111 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5113 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5114 | // Since we have proxy, should use full url |
| 5115 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5116 | MockWrite( |
| 5117 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5118 | "Host: www.example.org\r\n" |
| 5119 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5120 | }; |
| 5121 | |
| 5122 | MockRead data_reads1[] = { |
| 5123 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5124 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5125 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5126 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5127 | }; |
| 5128 | |
| 5129 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5130 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5131 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5132 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5133 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5134 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5135 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5136 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5137 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5139 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5140 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5141 | |
| 5142 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5143 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5144 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5145 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5146 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5147 | TestLoadTimingNotReused(load_timing_info, |
| 5148 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5149 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5150 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5151 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5152 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5153 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5154 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5155 | EXPECT_EQ(200, response->headers->response_code()); |
| 5156 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5157 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5158 | |
| 5159 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5160 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5161 | } |
| 5162 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5163 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5164 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5165 | HttpRequestInfo request; |
| 5166 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5167 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5168 | request.traffic_annotation = |
| 5169 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5170 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5171 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5172 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5173 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5174 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5175 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5176 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5177 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5178 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5179 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5180 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5181 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5182 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5183 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5184 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5185 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5186 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5187 | }; |
| 5188 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5189 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5190 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5191 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5192 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5193 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5194 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5195 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5196 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5197 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5198 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5199 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5200 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5201 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5202 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5203 | |
| 5204 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5205 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5206 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5207 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5208 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5209 | TestLoadTimingNotReused(load_timing_info, |
| 5210 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5211 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5212 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5213 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5214 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5215 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5216 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5217 | |
| 5218 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5219 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5220 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5221 | } |
| 5222 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5223 | // Verifies that a session which races and wins against the owning transaction |
| 5224 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5225 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5226 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5227 | HttpRequestInfo request; |
| 5228 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5229 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5230 | request.traffic_annotation = |
| 5231 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5232 | |
| 5233 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5234 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5235 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5236 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5237 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5238 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5239 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5240 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5241 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5242 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5243 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5244 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5245 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5246 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5247 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5248 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5249 | }; |
| 5250 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5251 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5252 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5253 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5254 | |
| 5255 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5256 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5257 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5258 | |
| 5259 | TestCompletionCallback callback1; |
| 5260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5261 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5262 | |
| 5263 | // Stall the hostname resolution begun by the transaction. |
| 5264 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 5265 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5266 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5267 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5268 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5269 | |
| 5270 | // Race a session to the proxy, which completes first. |
| 5271 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5272 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
| 5273 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5274 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5275 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5276 | |
| 5277 | // Unstall the resolution begun by the transaction. |
| 5278 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5279 | session_deps_.host_resolver->ResolveAllPending(); |
| 5280 | |
| 5281 | EXPECT_FALSE(callback1.have_result()); |
| 5282 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5283 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5284 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5285 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5286 | ASSERT_TRUE(response); |
| 5287 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5288 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5289 | |
| 5290 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5291 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5292 | EXPECT_EQ(kUploadData, response_data); |
| 5293 | } |
| 5294 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5295 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5296 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5297 | HttpRequestInfo request; |
| 5298 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5299 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5300 | request.traffic_annotation = |
| 5301 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5302 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5303 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5304 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5305 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5306 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5307 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5308 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5309 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5310 | // The first request will be a bare GET, the second request will be a |
| 5311 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5312 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5313 | SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5314 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5315 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5316 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5317 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5318 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5319 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 5320 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5321 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5322 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5323 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5324 | }; |
| 5325 | |
| 5326 | // The first response is a 407 proxy authentication challenge, and the second |
| 5327 | // response will be a 200 response since the second request includes a valid |
| 5328 | // Authorization header. |
| 5329 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5330 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5331 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5332 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 5333 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5334 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 5335 | SpdySerializedFrame body_authentication( |
| 5336 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5337 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5338 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5339 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5340 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5341 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5342 | CreateMockRead(resp_data, 4), |
| 5343 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5344 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5345 | }; |
| 5346 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5347 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5348 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5349 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5350 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5351 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5352 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5353 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5354 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5355 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5356 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5357 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5358 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5359 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5361 | |
| 5362 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5363 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5364 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5365 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5366 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5367 | ASSERT_TRUE(response); |
| 5368 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5369 | EXPECT_EQ(407, response->headers->response_code()); |
| 5370 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5371 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5372 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5373 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5374 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5375 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5376 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5377 | |
| 5378 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5379 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5380 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5381 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5382 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5383 | ASSERT_TRUE(response_restart); |
| 5384 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5385 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5386 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5387 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5388 | } |
| 5389 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5390 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5391 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5392 | HttpRequestInfo request; |
| 5393 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5394 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5395 | request.traffic_annotation = |
| 5396 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5397 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5398 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5399 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5400 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5401 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5402 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5403 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5404 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5405 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5406 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5407 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5408 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5409 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5410 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5411 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5412 | const char get[] = |
| 5413 | "GET / HTTP/1.1\r\n" |
| 5414 | "Host: www.example.org\r\n" |
| 5415 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5416 | SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5417 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5418 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5419 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5420 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5421 | SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5422 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5423 | SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5424 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5425 | SpdySerializedFrame window_update( |
| 5426 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5427 | |
| 5428 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5429 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5430 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5431 | }; |
| 5432 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5433 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5434 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5435 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5436 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5437 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5438 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5439 | }; |
| 5440 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5441 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5442 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5443 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5444 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5445 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5446 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5447 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5448 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5449 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5451 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5452 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5453 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5454 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5455 | |
| 5456 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5457 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5458 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5459 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5460 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5461 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5462 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5463 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5464 | ASSERT_TRUE(response); |
| 5465 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5466 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5467 | |
| 5468 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5469 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5470 | EXPECT_EQ("1234567890", response_data); |
| 5471 | } |
| 5472 | |
| 5473 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5474 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5475 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5476 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5477 | HttpRequestInfo request; |
| 5478 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5479 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5480 | request.traffic_annotation = |
| 5481 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5482 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5483 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5484 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5485 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5486 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5487 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5488 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5489 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5490 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5491 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5492 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5493 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5494 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5495 | // fetch https://www.example.org/ via SPDY |
| 5496 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5497 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5498 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5499 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5500 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5501 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5502 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5503 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5504 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5505 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5506 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5507 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5508 | SpdySerializedFrame window_update_get_resp( |
| 5509 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 5510 | SpdySerializedFrame window_update_body( |
| 5511 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5512 | |
| 5513 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5514 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5515 | CreateMockWrite(window_update_get_resp, 6), |
| 5516 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5517 | }; |
| 5518 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5519 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5520 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5521 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5522 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5523 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5524 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5525 | }; |
| 5526 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5527 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5528 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5529 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5530 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5531 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5532 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5533 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5534 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5535 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5536 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5537 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5538 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5539 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5540 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5541 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5542 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5543 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5544 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5545 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5546 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5547 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5548 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5549 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5550 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5551 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5552 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5553 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5554 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5555 | ASSERT_TRUE(response); |
| 5556 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5557 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5558 | |
| 5559 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5560 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5561 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5562 | } |
| 5563 | |
| 5564 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5565 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5566 | HttpRequestInfo request; |
| 5567 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5568 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5569 | request.traffic_annotation = |
| 5570 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5571 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5572 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5573 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5574 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5575 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5576 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5577 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5578 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5579 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5580 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5581 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5582 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5583 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5584 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5585 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5586 | |
| 5587 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5588 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5589 | }; |
| 5590 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5591 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5592 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5593 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5594 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5595 | }; |
| 5596 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5597 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5598 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5599 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5600 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5601 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5602 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5603 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5604 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5605 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5607 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5608 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5609 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5610 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5611 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5612 | |
| 5613 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5614 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5615 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5616 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5617 | } |
| 5618 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5619 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5620 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5621 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5622 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5623 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5624 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5625 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5626 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5627 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5628 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5629 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5630 | |
| 5631 | HttpRequestInfo request1; |
| 5632 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5633 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5634 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5635 | request1.traffic_annotation = |
| 5636 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5637 | |
| 5638 | HttpRequestInfo request2; |
| 5639 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5640 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5641 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5642 | request2.traffic_annotation = |
| 5643 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5644 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5645 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5646 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5647 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5648 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5649 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5650 | // Fetch https://www.example.org/ via HTTP. |
| 5651 | const char get1[] = |
| 5652 | "GET / HTTP/1.1\r\n" |
| 5653 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5654 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5655 | SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5656 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5657 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5658 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5659 | SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5660 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5661 | SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5662 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5663 | SpdySerializedFrame window_update( |
| 5664 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5665 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5666 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5667 | SpdyHeaderBlock connect2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 5668 | connect2_block[kHttp2MethodHeader] = "CONNECT"; |
| 5669 | connect2_block[kHttp2AuthorityHeader] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5670 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5671 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5672 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5673 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5674 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5675 | // Fetch https://mail.example.org/ via HTTP. |
| 5676 | const char get2[] = |
| 5677 | "GET / HTTP/1.1\r\n" |
| 5678 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5679 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5680 | SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5681 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5682 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5683 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5684 | SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5685 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5686 | SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5687 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5688 | |
| 5689 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5690 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5691 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5692 | }; |
| 5693 | |
| 5694 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5695 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5696 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5697 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5698 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5699 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5700 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5701 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5702 | }; |
| 5703 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5704 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5705 | arraysize(spdy_writes)); |
| 5706 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5707 | |
| 5708 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5709 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5710 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5711 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5712 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5713 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5714 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5715 | |
| 5716 | TestCompletionCallback callback; |
| 5717 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5718 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5719 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5720 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5721 | |
| 5722 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5723 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5724 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5725 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5726 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5727 | ASSERT_TRUE(response); |
| 5728 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5729 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5730 | |
| 5731 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5732 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5733 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5734 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5735 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5736 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5737 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5738 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5739 | |
| 5740 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5741 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5742 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5743 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5744 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5745 | |
| 5746 | // The requests should have different IDs, since they each are using their own |
| 5747 | // separate stream. |
| 5748 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5749 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5750 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5751 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5752 | } |
| 5753 | |
| 5754 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5755 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5756 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5757 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5758 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5759 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5760 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5761 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5762 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5763 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5764 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5765 | |
| 5766 | HttpRequestInfo request1; |
| 5767 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5768 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5769 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5770 | request1.traffic_annotation = |
| 5771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5772 | |
| 5773 | HttpRequestInfo request2; |
| 5774 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5775 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5776 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5777 | request2.traffic_annotation = |
| 5778 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5779 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5780 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5781 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5782 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5783 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5784 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5785 | // Fetch https://www.example.org/ via HTTP. |
| 5786 | const char get1[] = |
| 5787 | "GET / HTTP/1.1\r\n" |
| 5788 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5789 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5790 | SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5791 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5792 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5793 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5794 | SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5795 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5796 | SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5797 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5798 | SpdySerializedFrame window_update( |
| 5799 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5800 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5801 | // Fetch https://www.example.org/2 via HTTP. |
| 5802 | const char get2[] = |
| 5803 | "GET /2 HTTP/1.1\r\n" |
| 5804 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5805 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5806 | SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5807 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5808 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5809 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5810 | SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5811 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5812 | SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5813 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5814 | |
| 5815 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5816 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5817 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5818 | }; |
| 5819 | |
| 5820 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5821 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5822 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5823 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5824 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5825 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5826 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5827 | }; |
| 5828 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5829 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5830 | arraysize(spdy_writes)); |
| 5831 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5832 | |
| 5833 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5834 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5835 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5836 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5837 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5838 | |
| 5839 | TestCompletionCallback callback; |
| 5840 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5841 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5842 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5843 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5844 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5845 | |
| 5846 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5847 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5848 | |
| 5849 | LoadTimingInfo load_timing_info; |
| 5850 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5851 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5852 | |
| 5853 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5854 | ASSERT_TRUE(response); |
| 5855 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5856 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5857 | |
| 5858 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5859 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5860 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5861 | trans.reset(); |
| 5862 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5863 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5864 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5865 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5866 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5867 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5868 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5869 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5870 | |
| 5871 | LoadTimingInfo load_timing_info2; |
| 5872 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5873 | TestLoadTimingReused(load_timing_info2); |
| 5874 | |
| 5875 | // The requests should have the same ID. |
| 5876 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5877 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5878 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5879 | } |
| 5880 | |
| 5881 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5882 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5883 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5884 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5885 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5886 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5887 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5888 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5889 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5890 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5891 | |
| 5892 | HttpRequestInfo request1; |
| 5893 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5894 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5895 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5896 | request1.traffic_annotation = |
| 5897 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5898 | |
| 5899 | HttpRequestInfo request2; |
| 5900 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5901 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5902 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5903 | request2.traffic_annotation = |
| 5904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5905 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5906 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5907 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5908 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5909 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5910 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5911 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5912 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5913 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5914 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5915 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5916 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5917 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5918 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5919 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5920 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5921 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5922 | |
| 5923 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5924 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5925 | }; |
| 5926 | |
| 5927 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5928 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5929 | CreateMockRead(body1, 2, ASYNC), |
| 5930 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5931 | CreateMockRead(body2, 5, ASYNC), |
| 5932 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5933 | }; |
| 5934 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5935 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5936 | arraysize(spdy_writes)); |
| 5937 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5938 | |
| 5939 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5940 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5941 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5942 | |
| 5943 | TestCompletionCallback callback; |
| 5944 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5945 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5946 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5947 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5948 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5949 | |
| 5950 | LoadTimingInfo load_timing_info; |
| 5951 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5952 | TestLoadTimingNotReused(load_timing_info, |
| 5953 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5954 | |
| 5955 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5956 | ASSERT_TRUE(response); |
| 5957 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5958 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5959 | |
| 5960 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5961 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5962 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5963 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5964 | // Delete the first request, so the second one can reuse the socket. |
| 5965 | trans.reset(); |
| 5966 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5967 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5968 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5969 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5970 | |
| 5971 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5972 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5973 | TestLoadTimingReused(load_timing_info2); |
| 5974 | |
| 5975 | // The requests should have the same ID. |
| 5976 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5977 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5978 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5979 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5980 | } |
| 5981 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5982 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5983 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5984 | HttpRequestInfo request; |
| 5985 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5986 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5987 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5988 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5989 | request.traffic_annotation = |
| 5990 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5991 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5992 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5993 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5994 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5995 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5996 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5997 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5998 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5999 | // Since we have proxy, should use full url |
| 6000 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6001 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6002 | "Host: www.example.org\r\n" |
| 6003 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6004 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6005 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6006 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6007 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6008 | "Host: www.example.org\r\n" |
| 6009 | "Proxy-Connection: keep-alive\r\n" |
| 6010 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6011 | }; |
| 6012 | |
| 6013 | // The proxy responds to the GET with a 407, using a persistent |
| 6014 | // connection. |
| 6015 | MockRead data_reads1[] = { |
| 6016 | // No credentials. |
| 6017 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6018 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6019 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6020 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6021 | |
| 6022 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6023 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6024 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6025 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6026 | }; |
| 6027 | |
| 6028 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6029 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6030 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6031 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6032 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6033 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6034 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6035 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6036 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6037 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6038 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6039 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6040 | |
| 6041 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6042 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6043 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6044 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6045 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6046 | TestLoadTimingNotReused(load_timing_info, |
| 6047 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6048 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6049 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6050 | ASSERT_TRUE(response); |
| 6051 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6052 | EXPECT_EQ(407, response->headers->response_code()); |
| 6053 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 6054 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6056 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6057 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6058 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6059 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6060 | |
| 6061 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6062 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6063 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6064 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6065 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6066 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6067 | TestLoadTimingReused(load_timing_info); |
| 6068 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6069 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6070 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6071 | |
| 6072 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6073 | EXPECT_EQ(200, response->headers->response_code()); |
| 6074 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6075 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6076 | |
| 6077 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6078 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6079 | } |
| 6080 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6081 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6082 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6083 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6084 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6085 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6086 | request.traffic_annotation = |
| 6087 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6088 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6089 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6090 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6091 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6092 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6093 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6094 | // Since we have proxy, should try to establish tunnel. |
| 6095 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6096 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6097 | "Host: www.example.org:443\r\n" |
| 6098 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6099 | }; |
| 6100 | |
| 6101 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6102 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6103 | // No response body because the test stops reading here. |
| 6104 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6105 | }; |
| 6106 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6107 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6108 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6109 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6110 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6111 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6112 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6113 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6114 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6115 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6117 | |
| 6118 | rv = callback.WaitForResult(); |
| 6119 | EXPECT_EQ(expected_status, rv); |
| 6120 | } |
| 6121 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6122 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6123 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6124 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6125 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6126 | } |
| 6127 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6128 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6129 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6130 | } |
| 6131 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6132 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6133 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6134 | } |
| 6135 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6136 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6137 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6138 | } |
| 6139 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6140 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6141 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6142 | } |
| 6143 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6144 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6145 | ConnectStatusHelper( |
| 6146 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6147 | } |
| 6148 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6149 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6150 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6151 | } |
| 6152 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6153 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6154 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6155 | } |
| 6156 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6157 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6158 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6159 | } |
| 6160 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6161 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6162 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6163 | } |
| 6164 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6165 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6166 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6167 | } |
| 6168 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6169 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6170 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6171 | } |
| 6172 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6173 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6174 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6175 | } |
| 6176 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6177 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6178 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6179 | } |
| 6180 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6181 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6182 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6183 | } |
| 6184 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6185 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6186 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6187 | } |
| 6188 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6189 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6190 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6191 | } |
| 6192 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6193 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6194 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6195 | } |
| 6196 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6197 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6198 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6199 | } |
| 6200 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6201 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6202 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6203 | } |
| 6204 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6205 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6206 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6207 | } |
| 6208 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6209 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6210 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6211 | } |
| 6212 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6213 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6214 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6215 | } |
| 6216 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6217 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6218 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6219 | } |
| 6220 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6221 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6222 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6223 | } |
| 6224 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6225 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6226 | ConnectStatusHelperWithExpectedStatus( |
| 6227 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6228 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6229 | } |
| 6230 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6231 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6232 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6233 | } |
| 6234 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6235 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6236 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6237 | } |
| 6238 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6239 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6240 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6241 | } |
| 6242 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6243 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6244 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6245 | } |
| 6246 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6247 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6248 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6249 | } |
| 6250 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6251 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6252 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6253 | } |
| 6254 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6255 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6256 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6257 | } |
| 6258 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6259 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6260 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6261 | } |
| 6262 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6263 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6264 | ConnectStatusHelper( |
| 6265 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6266 | } |
| 6267 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6268 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6269 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6270 | } |
| 6271 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6272 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6273 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6274 | } |
| 6275 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6276 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6277 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6278 | } |
| 6279 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6280 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6281 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6282 | } |
| 6283 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6284 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6285 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6286 | } |
| 6287 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6288 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6289 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6290 | } |
| 6291 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6292 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6293 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6294 | } |
| 6295 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6296 | // Test the flow when both the proxy server AND origin server require |
| 6297 | // authentication. Again, this uses basic auth for both since that is |
| 6298 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6299 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6300 | HttpRequestInfo request; |
| 6301 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6302 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6303 | request.traffic_annotation = |
| 6304 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6305 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6306 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6307 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6308 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6309 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6310 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6311 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6312 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6313 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6314 | MockWrite( |
| 6315 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6316 | "Host: www.example.org\r\n" |
| 6317 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6318 | }; |
| 6319 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6320 | MockRead data_reads1[] = { |
| 6321 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6322 | // Give a couple authenticate options (only the middle one is actually |
| 6323 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6324 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6325 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6326 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6327 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6328 | // Large content-length -- won't matter, as connection will be reset. |
| 6329 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6330 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6331 | }; |
| 6332 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6333 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6334 | // request we should be issuing -- the final header line contains the |
| 6335 | // proxy's credentials. |
| 6336 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6337 | MockWrite( |
| 6338 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6339 | "Host: www.example.org\r\n" |
| 6340 | "Proxy-Connection: keep-alive\r\n" |
| 6341 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6342 | }; |
| 6343 | |
| 6344 | // Now the proxy server lets the request pass through to origin server. |
| 6345 | // The origin server responds with a 401. |
| 6346 | MockRead data_reads2[] = { |
| 6347 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6348 | // Note: We are using the same realm-name as the proxy server. This is |
| 6349 | // completely valid, as realms are unique across hosts. |
| 6350 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6351 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6352 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6353 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6354 | }; |
| 6355 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6356 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6357 | // the credentials for both the proxy and origin server. |
| 6358 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6359 | MockWrite( |
| 6360 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6361 | "Host: www.example.org\r\n" |
| 6362 | "Proxy-Connection: keep-alive\r\n" |
| 6363 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 6364 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6365 | }; |
| 6366 | |
| 6367 | // Lastly we get the desired content. |
| 6368 | MockRead data_reads3[] = { |
| 6369 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6370 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6371 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6372 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6373 | }; |
| 6374 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6375 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6376 | data_writes1, arraysize(data_writes1)); |
| 6377 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6378 | data_writes2, arraysize(data_writes2)); |
| 6379 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6380 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6381 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6382 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6383 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6385 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6386 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6387 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6388 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6389 | |
| 6390 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6391 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6392 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6393 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6394 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6395 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6396 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6397 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6398 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6399 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6400 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6401 | |
| 6402 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6403 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6404 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6405 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6406 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6407 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6408 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6409 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6410 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6411 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 6412 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6413 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6414 | |
| 6415 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6416 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6417 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6418 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6419 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6420 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6421 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6422 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6423 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 6424 | // can't hook into its internals to cause it to generate predictable NTLM |
| 6425 | // authorization headers. |
| 6426 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6427 | // The NTLM authentication unit tests are based on known test data from the |
| 6428 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 6429 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 6430 | // for the implementation and testing of the protocol. |
| 6431 | // |
| 6432 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6433 | |
| 6434 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6435 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6436 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6437 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6438 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6439 | request.traffic_annotation = |
| 6440 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6441 | |
| 6442 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6443 | // to other auth schemes. |
| 6444 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6445 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6446 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6447 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6448 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6449 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6450 | // Generate the NTLM messages based on known test data. |
| 6451 | std::string negotiate_msg; |
| 6452 | std::string challenge_msg; |
| 6453 | std::string authenticate_msg; |
| 6454 | base::Base64Encode( |
| 6455 | base::StringPiece( |
| 6456 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6457 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6458 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6459 | base::Base64Encode( |
| 6460 | base::StringPiece( |
| 6461 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6462 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6463 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6464 | base::Base64Encode( |
| 6465 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6466 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6467 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6468 | arraysize( |
| 6469 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6470 | &authenticate_msg); |
| 6471 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6472 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6473 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6474 | "Host: server\r\n" |
| 6475 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6476 | }; |
| 6477 | |
| 6478 | MockRead data_reads1[] = { |
| 6479 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6480 | // Negotiate and NTLM are often requested together. However, we only want |
| 6481 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6482 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6483 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6484 | MockRead("Connection: close\r\n"), |
| 6485 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6486 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6487 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6488 | }; |
| 6489 | |
| 6490 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6491 | // After restarting with a null identity, this is the |
| 6492 | // request we should be issuing -- the final header line contains a Type |
| 6493 | // 1 message. |
| 6494 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6495 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6496 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6497 | "Authorization: NTLM "), |
| 6498 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6499 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6500 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6501 | // (using correct credentials). The second request continues on the |
| 6502 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6503 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6504 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6505 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6506 | "Authorization: NTLM "), |
| 6507 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6508 | }; |
| 6509 | |
| 6510 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6511 | // The origin server responds with a Type 2 message. |
| 6512 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6513 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6514 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6515 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6516 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6517 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6518 | // Lastly we get the desired content. |
| 6519 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6520 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6521 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6522 | }; |
| 6523 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6524 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6525 | data_writes1, arraysize(data_writes1)); |
| 6526 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6527 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6528 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6529 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6530 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6531 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6532 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6533 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6534 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6535 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6536 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6538 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6539 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6540 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6541 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6542 | |
| 6543 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6544 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6545 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6546 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6547 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6548 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6549 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6550 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6551 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6552 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6553 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6554 | rv = trans.RestartWithAuth( |
| 6555 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6556 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6557 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6558 | |
| 6559 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6560 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6561 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6562 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6563 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6564 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6565 | ASSERT_TRUE(response); |
| 6566 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6567 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6568 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6569 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6570 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6571 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6572 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6573 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6574 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6575 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6576 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6577 | ASSERT_TRUE(response); |
| 6578 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6579 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6580 | |
| 6581 | std::string response_data; |
| 6582 | rv = ReadTransaction(&trans, &response_data); |
| 6583 | EXPECT_THAT(rv, IsOk()); |
| 6584 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6585 | |
| 6586 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6587 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6588 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6589 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6590 | } |
| 6591 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6592 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6593 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6594 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6595 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6596 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6597 | request.traffic_annotation = |
| 6598 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6599 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6600 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6601 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6602 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6603 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6604 | // Generate the NTLM messages based on known test data. |
| 6605 | std::string negotiate_msg; |
| 6606 | std::string challenge_msg; |
| 6607 | std::string authenticate_msg; |
| 6608 | base::Base64Encode( |
| 6609 | base::StringPiece( |
| 6610 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6611 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6612 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6613 | base::Base64Encode( |
| 6614 | base::StringPiece( |
| 6615 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6616 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6617 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6618 | base::Base64Encode( |
| 6619 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6620 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6621 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6622 | arraysize( |
| 6623 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6624 | &authenticate_msg); |
| 6625 | |
| 6626 | // The authenticate message when |kWrongPassword| is sent. |
| 6627 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6628 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 6629 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 6630 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 6631 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 6632 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 6633 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6634 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6635 | // Sanity check that it's the same length as the correct authenticate message |
| 6636 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6637 | ASSERT_EQ(authenticate_msg.length(), |
| 6638 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6639 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6640 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6641 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6642 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6643 | "Host: server\r\n" |
| 6644 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6645 | }; |
| 6646 | |
| 6647 | MockRead data_reads1[] = { |
| 6648 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6649 | // Negotiate and NTLM are often requested together. However, we only want |
| 6650 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6651 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6652 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6653 | MockRead("Connection: close\r\n"), |
| 6654 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6655 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6656 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6657 | }; |
| 6658 | |
| 6659 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6660 | // After restarting with a null identity, this is the |
| 6661 | // request we should be issuing -- the final header line contains a Type |
| 6662 | // 1 message. |
| 6663 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6664 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6665 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6666 | "Authorization: NTLM "), |
| 6667 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6668 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6669 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6670 | // (using incorrect credentials). The second request continues on the |
| 6671 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6672 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6673 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6674 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6675 | "Authorization: NTLM "), |
| 6676 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6677 | }; |
| 6678 | |
| 6679 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6680 | // The origin server responds with a Type 2 message. |
| 6681 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6682 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6683 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 6684 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6685 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6686 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6687 | // Wrong password. |
| 6688 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6689 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 6690 | MockRead("Content-Length: 42\r\n"), |
| 6691 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6692 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6693 | }; |
| 6694 | |
| 6695 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6696 | // After restarting with a null identity, this is the |
| 6697 | // request we should be issuing -- the final header line contains a Type |
| 6698 | // 1 message. |
| 6699 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6700 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6701 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6702 | "Authorization: NTLM "), |
| 6703 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6704 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6705 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6706 | // (the credentials for the origin server). The second request continues |
| 6707 | // on the same connection. |
| 6708 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6709 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6710 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6711 | "Authorization: NTLM "), |
| 6712 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6713 | }; |
| 6714 | |
| 6715 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6716 | // The origin server responds with a Type 2 message. |
| 6717 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6718 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6719 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6720 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6721 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6722 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6723 | // Lastly we get the desired content. |
| 6724 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6725 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6726 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6727 | }; |
| 6728 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6729 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6730 | data_writes1, arraysize(data_writes1)); |
| 6731 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6732 | data_writes2, arraysize(data_writes2)); |
| 6733 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6734 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6735 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6736 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6737 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6738 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6739 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6740 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6741 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6742 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6743 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6744 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6745 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6746 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6747 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6748 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6749 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6750 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6751 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6752 | |
| 6753 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6754 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6755 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6756 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6757 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6758 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6759 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6760 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6761 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6762 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6763 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6764 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6765 | rv = trans.RestartWithAuth( |
| 6766 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 6767 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6768 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6769 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6770 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6771 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6772 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6773 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6774 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6775 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6776 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6777 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6778 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6779 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6780 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6781 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6782 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6783 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6784 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6785 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6786 | |
| 6787 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6788 | rv = trans.RestartWithAuth( |
| 6789 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6790 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6791 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6792 | |
| 6793 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6794 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6796 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6798 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6799 | |
| 6800 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6801 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6802 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6803 | |
| 6804 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6805 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6806 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6807 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6808 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6809 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6810 | |
| 6811 | std::string response_data; |
| 6812 | rv = ReadTransaction(&trans, &response_data); |
| 6813 | EXPECT_THAT(rv, IsOk()); |
| 6814 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6815 | |
| 6816 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6817 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6818 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6819 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6820 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6821 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6822 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6823 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6824 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 6825 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6826 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6827 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6828 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6829 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6830 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6831 | |
| 6832 | HttpRequestInfo request; |
| 6833 | request.method = "GET"; |
| 6834 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6835 | request.traffic_annotation = |
| 6836 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6837 | |
| 6838 | // First request without credentials. |
| 6839 | SpdyHeaderBlock request_headers0(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6840 | SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
| 6841 | 1, std::move(request_headers0), LOWEST, true)); |
| 6842 | |
| 6843 | SpdyHeaderBlock response_headers0; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 6844 | response_headers0[kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6845 | response_headers0["www-authenticate"] = "NTLM"; |
| 6846 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
| 6847 | 1, std::move(response_headers0), true)); |
| 6848 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6849 | // Stream 1 is closed. |
| 6850 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6851 | |
| 6852 | // Generate the NTLM messages based on known test data. |
| 6853 | std::string negotiate_msg; |
| 6854 | std::string challenge_msg; |
| 6855 | std::string authenticate_msg; |
| 6856 | base::Base64Encode( |
| 6857 | base::StringPiece( |
| 6858 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6859 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6860 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6861 | base::Base64Encode( |
| 6862 | base::StringPiece( |
| 6863 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6864 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6865 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6866 | base::Base64Encode( |
| 6867 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6868 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6869 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6870 | arraysize( |
| 6871 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6872 | &authenticate_msg); |
| 6873 | |
| 6874 | // Retry with authorization header. |
| 6875 | SpdyHeaderBlock request_headers1(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6876 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
| 6877 | SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
| 6878 | 3, std::move(request_headers1), LOWEST, true)); |
| 6879 | |
| 6880 | SpdySerializedFrame rst( |
| 6881 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_HTTP_1_1_REQUIRED)); |
| 6882 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6883 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 6884 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6885 | |
| 6886 | // Retry yet again using HTTP/1.1. |
| 6887 | MockWrite writes1[] = { |
| 6888 | // After restarting with a null identity, this is the |
| 6889 | // request we should be issuing -- the final header line contains a Type |
| 6890 | // 1 message. |
| 6891 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6892 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6893 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6894 | "Authorization: NTLM "), |
| 6895 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6896 | |
| 6897 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6898 | // (the credentials for the origin server). The second request continues |
| 6899 | // on the same connection. |
| 6900 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6901 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6902 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6903 | "Authorization: NTLM "), |
| 6904 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6905 | }; |
| 6906 | |
| 6907 | MockRead reads1[] = { |
| 6908 | // The origin server responds with a Type 2 message. |
| 6909 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6910 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6911 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6912 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6913 | MockRead("You are not authorized to view this page\r\n"), |
| 6914 | |
| 6915 | // Lastly we get the desired content. |
| 6916 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6917 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6918 | 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] | 6919 | }; |
| 6920 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 6921 | arraysize(writes0)); |
| 6922 | StaticSocketDataProvider data1(reads1, arraysize(reads1), writes1, |
| 6923 | arraysize(writes1)); |
| 6924 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6925 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6926 | |
| 6927 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6928 | ssl0.next_proto = kProtoHTTP2; |
| 6929 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6930 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6931 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6932 | |
| 6933 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6934 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6935 | |
| 6936 | TestCompletionCallback callback1; |
| 6937 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6938 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6939 | |
| 6940 | rv = callback1.WaitForResult(); |
| 6941 | EXPECT_THAT(rv, IsOk()); |
| 6942 | |
| 6943 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6944 | |
| 6945 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6946 | ASSERT_TRUE(response); |
| 6947 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6948 | |
| 6949 | TestCompletionCallback callback2; |
| 6950 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6951 | rv = trans.RestartWithAuth( |
| 6952 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6953 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6954 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6955 | |
| 6956 | rv = callback2.WaitForResult(); |
| 6957 | EXPECT_THAT(rv, IsOk()); |
| 6958 | |
| 6959 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6960 | |
| 6961 | response = trans.GetResponseInfo(); |
| 6962 | ASSERT_TRUE(response); |
| 6963 | EXPECT_FALSE(response->auth_challenge); |
| 6964 | |
| 6965 | TestCompletionCallback callback3; |
| 6966 | |
| 6967 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6968 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6969 | |
| 6970 | rv = callback3.WaitForResult(); |
| 6971 | EXPECT_THAT(rv, IsOk()); |
| 6972 | |
| 6973 | response = trans.GetResponseInfo(); |
| 6974 | ASSERT_TRUE(response); |
| 6975 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6976 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6977 | |
| 6978 | std::string response_data; |
| 6979 | rv = ReadTransaction(&trans, &response_data); |
| 6980 | EXPECT_THAT(rv, IsOk()); |
| 6981 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6982 | |
| 6983 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6984 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6985 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6986 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6987 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6988 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6989 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6990 | // Test reading a server response which has only headers, and no body. |
| 6991 | // After some maximum number of bytes is consumed, the transaction should |
| 6992 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6993 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6994 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6995 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6996 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6997 | request.traffic_annotation = |
| 6998 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6999 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7000 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7001 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7002 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7003 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7004 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7005 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7006 | |
| 7007 | MockRead data_reads[] = { |
| 7008 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7009 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7010 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7011 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7012 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7013 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7014 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7015 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7016 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7017 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7018 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7019 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7020 | |
| 7021 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7022 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7023 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7024 | |
| 7025 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7026 | // establish tunnel. |
| 7027 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7028 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7029 | HttpRequestInfo request; |
| 7030 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7031 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7032 | request.traffic_annotation = |
| 7033 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7034 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7035 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7036 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7037 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7038 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7040 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7041 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7042 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7043 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7044 | // Since we have proxy, should try to establish tunnel. |
| 7045 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7046 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7047 | "Host: www.example.org:443\r\n" |
| 7048 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7049 | }; |
| 7050 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7051 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7052 | // connection. Usually a proxy would return 501 (not implemented), |
| 7053 | // or 200 (tunnel established). |
| 7054 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7055 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7056 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7057 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7058 | }; |
| 7059 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7060 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7061 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7062 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7063 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7064 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7065 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7066 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7067 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7068 | |
| 7069 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7070 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7071 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7072 | // Empty the current queue. This is necessary because idle sockets are |
| 7073 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7074 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7075 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7076 | // We now check to make sure the TCPClientSocket was not added back to |
| 7077 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7078 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7079 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7080 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7081 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7082 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7083 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7084 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7085 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7086 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7087 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7088 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7089 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7090 | request.traffic_annotation = |
| 7091 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7092 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7093 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7095 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7096 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7097 | MockRead data_reads[] = { |
| 7098 | // A part of the response body is received with the response headers. |
| 7099 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7100 | // The rest of the response body is received in two parts. |
| 7101 | MockRead("lo"), |
| 7102 | MockRead(" world"), |
| 7103 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7104 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7105 | }; |
| 7106 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7107 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7108 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7109 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7110 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7111 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7112 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7113 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7114 | |
| 7115 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7116 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7117 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7118 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7119 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7120 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7121 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7122 | std::string status_line = response->headers->GetStatusLine(); |
| 7123 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7124 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7125 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7126 | |
| 7127 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7128 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7129 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7130 | EXPECT_EQ("hello world", response_data); |
| 7131 | |
| 7132 | // Empty the current queue. This is necessary because idle sockets are |
| 7133 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7134 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7135 | |
| 7136 | // 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] | 7137 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7138 | } |
| 7139 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7140 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7141 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7142 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7143 | HttpRequestInfo request; |
| 7144 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7145 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7146 | request.traffic_annotation = |
| 7147 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7148 | |
| 7149 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7150 | MockWrite( |
| 7151 | "GET / HTTP/1.1\r\n" |
| 7152 | "Host: www.example.org\r\n" |
| 7153 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7154 | }; |
| 7155 | |
| 7156 | MockRead data_reads[] = { |
| 7157 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7158 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7159 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7160 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7161 | }; |
| 7162 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7163 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7165 | |
| 7166 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7167 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7168 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7169 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7170 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7171 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7173 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7174 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7175 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7176 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7177 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7178 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7179 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7180 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7181 | ASSERT_TRUE(response); |
| 7182 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7183 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7184 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7185 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7186 | |
| 7187 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7188 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7189 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7190 | EXPECT_EQ("hello world", response_data); |
| 7191 | |
| 7192 | // Empty the current queue. This is necessary because idle sockets are |
| 7193 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7194 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7195 | |
| 7196 | // 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] | 7197 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7198 | } |
| 7199 | |
| 7200 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 7201 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7202 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7203 | HttpRequestInfo request; |
| 7204 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7205 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7206 | request.traffic_annotation = |
| 7207 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7208 | |
| 7209 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7210 | MockWrite( |
| 7211 | "GET / HTTP/1.1\r\n" |
| 7212 | "Host: www.example.org\r\n" |
| 7213 | "Connection: keep-alive\r\n\r\n"), |
| 7214 | MockWrite( |
| 7215 | "GET / HTTP/1.1\r\n" |
| 7216 | "Host: www.example.org\r\n" |
| 7217 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7218 | }; |
| 7219 | |
| 7220 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 7221 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7222 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7223 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7224 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7225 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7226 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7227 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7228 | |
| 7229 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7230 | data_writes, arraysize(data_writes)); |
| 7231 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 7232 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7233 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7234 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7236 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7237 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7238 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7239 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7240 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7241 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7242 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7243 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7244 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7245 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7246 | |
| 7247 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7248 | ASSERT_TRUE(response); |
| 7249 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7250 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7251 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7252 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7253 | |
| 7254 | std::string response_data; |
| 7255 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7256 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7257 | EXPECT_EQ("hello world", response_data); |
| 7258 | |
| 7259 | // Empty the current queue. This is necessary because idle sockets are |
| 7260 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7261 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7262 | |
| 7263 | // 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] | 7264 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7265 | |
| 7266 | // Now start the second transaction, which should reuse the previous socket. |
| 7267 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7268 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7269 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7270 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7271 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7272 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7273 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7274 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7275 | |
| 7276 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7277 | ASSERT_TRUE(response); |
| 7278 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7279 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7280 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7281 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7282 | |
| 7283 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7284 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7285 | EXPECT_EQ("hello world", response_data); |
| 7286 | |
| 7287 | // Empty the current queue. This is necessary because idle sockets are |
| 7288 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7289 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7290 | |
| 7291 | // 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] | 7292 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7293 | } |
| 7294 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7295 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7296 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7297 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7298 | HttpRequestInfo request; |
| 7299 | request.method = "GET"; |
| 7300 | request.url = GURL("http://www.example.org/"); |
| 7301 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7302 | request.traffic_annotation = |
| 7303 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7304 | |
| 7305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7306 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7307 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7308 | |
| 7309 | MockRead data_reads[] = { |
| 7310 | // A part of the response body is received with the response headers. |
| 7311 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7312 | // The rest of the response body is received in two parts. |
| 7313 | MockRead("lo"), MockRead(" world"), |
| 7314 | MockRead("junk"), // Should not be read!! |
| 7315 | MockRead(SYNCHRONOUS, OK), |
| 7316 | }; |
| 7317 | |
| 7318 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7319 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7320 | |
| 7321 | TestCompletionCallback callback; |
| 7322 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7323 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7324 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7325 | |
| 7326 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7327 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7328 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7329 | ASSERT_TRUE(response); |
| 7330 | EXPECT_TRUE(response->headers); |
| 7331 | std::string status_line = response->headers->GetStatusLine(); |
| 7332 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7333 | |
| 7334 | // Make memory critical notification and ensure the transaction still has been |
| 7335 | // operating right. |
| 7336 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7337 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7338 | base::RunLoop().RunUntilIdle(); |
| 7339 | |
| 7340 | // Socket should not be flushed as long as it is not idle. |
| 7341 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7342 | |
| 7343 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7344 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7345 | EXPECT_THAT(rv, IsOk()); |
| 7346 | EXPECT_EQ("hello world", response_data); |
| 7347 | |
| 7348 | // Empty the current queue. This is necessary because idle sockets are |
| 7349 | // added to the connection pool asynchronously with a PostTask. |
| 7350 | base::RunLoop().RunUntilIdle(); |
| 7351 | |
| 7352 | // We now check to make sure the socket was added back to the pool. |
| 7353 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7354 | |
| 7355 | // Idle sockets should be flushed now. |
| 7356 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7357 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7358 | base::RunLoop().RunUntilIdle(); |
| 7359 | |
| 7360 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7361 | } |
| 7362 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7363 | // Disable idle socket closing on memory pressure. |
| 7364 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7365 | // low memory notification and ensure the socket pool is NOT flushed. |
| 7366 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 7367 | HttpRequestInfo request; |
| 7368 | request.method = "GET"; |
| 7369 | request.url = GURL("http://www.example.org/"); |
| 7370 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7371 | request.traffic_annotation = |
| 7372 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7373 | |
| 7374 | // Disable idle socket closing on memory pressure. |
| 7375 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 7376 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7377 | |
| 7378 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7379 | |
| 7380 | MockRead data_reads[] = { |
| 7381 | // A part of the response body is received with the response headers. |
| 7382 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7383 | // The rest of the response body is received in two parts. |
| 7384 | MockRead("lo"), MockRead(" world"), |
| 7385 | MockRead("junk"), // Should not be read!! |
| 7386 | MockRead(SYNCHRONOUS, OK), |
| 7387 | }; |
| 7388 | |
| 7389 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7390 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7391 | |
| 7392 | TestCompletionCallback callback; |
| 7393 | |
| 7394 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 7395 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7396 | |
| 7397 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7398 | |
| 7399 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7400 | ASSERT_TRUE(response); |
| 7401 | EXPECT_TRUE(response->headers); |
| 7402 | std::string status_line = response->headers->GetStatusLine(); |
| 7403 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7404 | |
| 7405 | // Make memory critical notification and ensure the transaction still has been |
| 7406 | // operating right. |
| 7407 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7408 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7409 | base::RunLoop().RunUntilIdle(); |
| 7410 | |
| 7411 | // Socket should not be flushed as long as it is not idle. |
| 7412 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7413 | |
| 7414 | std::string response_data; |
| 7415 | rv = ReadTransaction(&trans, &response_data); |
| 7416 | EXPECT_THAT(rv, IsOk()); |
| 7417 | EXPECT_EQ("hello world", response_data); |
| 7418 | |
| 7419 | // Empty the current queue. This is necessary because idle sockets are |
| 7420 | // added to the connection pool asynchronously with a PostTask. |
| 7421 | base::RunLoop().RunUntilIdle(); |
| 7422 | |
| 7423 | // We now check to make sure the socket was added back to the pool. |
| 7424 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7425 | |
| 7426 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 7427 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7428 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 7429 | base::RunLoop().RunUntilIdle(); |
| 7430 | |
| 7431 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7432 | |
| 7433 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 7434 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7435 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7436 | base::RunLoop().RunUntilIdle(); |
| 7437 | |
| 7438 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7439 | } |
| 7440 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7441 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 7442 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7443 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7444 | HttpRequestInfo request; |
| 7445 | request.method = "GET"; |
| 7446 | request.url = GURL("https://www.example.org/"); |
| 7447 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7448 | request.traffic_annotation = |
| 7449 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7450 | |
| 7451 | MockWrite data_writes[] = { |
| 7452 | MockWrite("GET / HTTP/1.1\r\n" |
| 7453 | "Host: www.example.org\r\n" |
| 7454 | "Connection: keep-alive\r\n\r\n"), |
| 7455 | }; |
| 7456 | |
| 7457 | MockRead data_reads[] = { |
| 7458 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7459 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 7460 | |
| 7461 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7463 | |
| 7464 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 7465 | arraysize(data_writes)); |
| 7466 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7467 | |
| 7468 | TestCompletionCallback callback; |
| 7469 | |
| 7470 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7471 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7472 | |
| 7473 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7474 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7475 | |
| 7476 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7479 | ASSERT_TRUE(response); |
| 7480 | ASSERT_TRUE(response->headers); |
| 7481 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7482 | |
| 7483 | // Make memory critical notification and ensure the transaction still has been |
| 7484 | // operating right. |
| 7485 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7486 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7487 | base::RunLoop().RunUntilIdle(); |
| 7488 | |
| 7489 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7490 | |
| 7491 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7492 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7493 | EXPECT_THAT(rv, IsOk()); |
| 7494 | EXPECT_EQ("hello world", response_data); |
| 7495 | |
| 7496 | // Empty the current queue. This is necessary because idle sockets are |
| 7497 | // added to the connection pool asynchronously with a PostTask. |
| 7498 | base::RunLoop().RunUntilIdle(); |
| 7499 | |
| 7500 | // We now check to make sure the socket was added back to the pool. |
| 7501 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7502 | |
| 7503 | // Make memory notification once again and ensure idle socket is closed. |
| 7504 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7505 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7506 | base::RunLoop().RunUntilIdle(); |
| 7507 | |
| 7508 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7509 | } |
| 7510 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7511 | // Make sure that we recycle a socket after a zero-length response. |
| 7512 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7513 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7514 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7515 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7516 | request.url = GURL( |
| 7517 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 7518 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 7519 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 7520 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7521 | request.traffic_annotation = |
| 7522 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7523 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7524 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7525 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7526 | MockRead data_reads[] = { |
| 7527 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 7528 | "Content-Length: 0\r\n" |
| 7529 | "Content-Type: text/html\r\n\r\n"), |
| 7530 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7531 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7532 | }; |
| 7533 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7534 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7535 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7536 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7537 | // Transaction must be created after the MockReads, so it's destroyed before |
| 7538 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7539 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7540 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7541 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7542 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7543 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7544 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7545 | |
| 7546 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7547 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7548 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7549 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7550 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7551 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7552 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7553 | std::string status_line = response->headers->GetStatusLine(); |
| 7554 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 7555 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7556 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7557 | |
| 7558 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7559 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7560 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7561 | EXPECT_EQ("", response_data); |
| 7562 | |
| 7563 | // Empty the current queue. This is necessary because idle sockets are |
| 7564 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7565 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7566 | |
| 7567 | // 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] | 7568 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7569 | } |
| 7570 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7571 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7572 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7573 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7574 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7575 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7576 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7577 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7578 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 7579 | // after use. |
| 7580 | request[0].method = "GET"; |
| 7581 | request[0].url = GURL("http://www.google.com/"); |
| 7582 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7583 | request[0].traffic_annotation = |
| 7584 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7585 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 7586 | // transaction 1. The first attempts fails when writing the POST data. |
| 7587 | // This causes the transaction to retry with a new socket. The second |
| 7588 | // attempt succeeds. |
| 7589 | request[1].method = "POST"; |
| 7590 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7591 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7592 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7593 | request[1].traffic_annotation = |
| 7594 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7595 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7596 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7597 | |
| 7598 | // The first socket is used for transaction 1 and the first attempt of |
| 7599 | // transaction 2. |
| 7600 | |
| 7601 | // The response of transaction 1. |
| 7602 | MockRead data_reads1[] = { |
| 7603 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 7604 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7605 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7606 | }; |
| 7607 | // The mock write results of transaction 1 and the first attempt of |
| 7608 | // transaction 2. |
| 7609 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7610 | MockWrite(SYNCHRONOUS, 64), // GET |
| 7611 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7612 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7613 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7614 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7615 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7616 | |
| 7617 | // The second socket is used for the second attempt of transaction 2. |
| 7618 | |
| 7619 | // The response of transaction 2. |
| 7620 | MockRead data_reads2[] = { |
| 7621 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 7622 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7623 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7624 | }; |
| 7625 | // The mock write results of the second attempt of transaction 2. |
| 7626 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7627 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7628 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7629 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7630 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7631 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7632 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7633 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7634 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7635 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7636 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7637 | "hello world", "welcome" |
| 7638 | }; |
| 7639 | |
| 7640 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7641 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7642 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7643 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7644 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7645 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7646 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7647 | |
| 7648 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7649 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7650 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7651 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7652 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7653 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7654 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7655 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7656 | |
| 7657 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7658 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7659 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7660 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7661 | } |
| 7662 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7663 | |
| 7664 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7665 | // 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] | 7666 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7667 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7668 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7669 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7670 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7671 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7672 | request.traffic_annotation = |
| 7673 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7674 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7675 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7676 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7677 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7678 | // The password contains an escaped character -- for this test to pass it |
| 7679 | // will need to be unescaped by HttpNetworkTransaction. |
| 7680 | EXPECT_EQ("b%40r", request.url.password()); |
| 7681 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7682 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7683 | MockWrite( |
| 7684 | "GET / HTTP/1.1\r\n" |
| 7685 | "Host: www.example.org\r\n" |
| 7686 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7687 | }; |
| 7688 | |
| 7689 | MockRead data_reads1[] = { |
| 7690 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7691 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7692 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7693 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7694 | }; |
| 7695 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7696 | // After the challenge above, the transaction will be restarted using the |
| 7697 | // identity from the url (foo, b@r) to answer the challenge. |
| 7698 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7699 | MockWrite( |
| 7700 | "GET / HTTP/1.1\r\n" |
| 7701 | "Host: www.example.org\r\n" |
| 7702 | "Connection: keep-alive\r\n" |
| 7703 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7704 | }; |
| 7705 | |
| 7706 | MockRead data_reads2[] = { |
| 7707 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7708 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7709 | MockRead(SYNCHRONOUS, OK), |
| 7710 | }; |
| 7711 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7712 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7713 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7714 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7715 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7716 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7717 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7718 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7719 | TestCompletionCallback callback1; |
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 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7723 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7724 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7725 | |
| 7726 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7727 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7728 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7729 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7730 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7731 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7732 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7733 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7734 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7735 | |
| 7736 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7737 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7738 | |
| 7739 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7740 | |
| 7741 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7742 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7743 | } |
| 7744 | |
| 7745 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7746 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7747 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7748 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7749 | HttpRequestInfo request; |
| 7750 | request.method = "GET"; |
| 7751 | // Note: the URL has a username:password in it. The password "baz" is |
| 7752 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7753 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7754 | |
| 7755 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7756 | request.traffic_annotation = |
| 7757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7758 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7759 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7760 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7761 | |
| 7762 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7763 | MockWrite( |
| 7764 | "GET / HTTP/1.1\r\n" |
| 7765 | "Host: www.example.org\r\n" |
| 7766 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7767 | }; |
| 7768 | |
| 7769 | MockRead data_reads1[] = { |
| 7770 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7771 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7772 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7773 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7774 | }; |
| 7775 | |
| 7776 | // After the challenge above, the transaction will be restarted using the |
| 7777 | // identity from the url (foo, baz) to answer the challenge. |
| 7778 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7779 | MockWrite( |
| 7780 | "GET / HTTP/1.1\r\n" |
| 7781 | "Host: www.example.org\r\n" |
| 7782 | "Connection: keep-alive\r\n" |
| 7783 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7784 | }; |
| 7785 | |
| 7786 | MockRead data_reads2[] = { |
| 7787 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7788 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7789 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7790 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7791 | }; |
| 7792 | |
| 7793 | // After the challenge above, the transaction will be restarted using the |
| 7794 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7795 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7796 | MockWrite( |
| 7797 | "GET / HTTP/1.1\r\n" |
| 7798 | "Host: www.example.org\r\n" |
| 7799 | "Connection: keep-alive\r\n" |
| 7800 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7801 | }; |
| 7802 | |
| 7803 | MockRead data_reads3[] = { |
| 7804 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7805 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7806 | MockRead(SYNCHRONOUS, OK), |
| 7807 | }; |
| 7808 | |
| 7809 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7810 | data_writes1, arraysize(data_writes1)); |
| 7811 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7812 | data_writes2, arraysize(data_writes2)); |
| 7813 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7814 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7815 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7816 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7817 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7818 | |
| 7819 | TestCompletionCallback callback1; |
| 7820 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7821 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7823 | |
| 7824 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7825 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7827 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7828 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7829 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7831 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7832 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7833 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7835 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7836 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7837 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7838 | |
| 7839 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7840 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7841 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7842 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7843 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7844 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7845 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7846 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7847 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7848 | |
| 7849 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7850 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7851 | |
| 7852 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7853 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7854 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7855 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7856 | } |
| 7857 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7858 | |
| 7859 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7860 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7861 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7862 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7863 | HttpRequestInfo request; |
| 7864 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7865 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7866 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7867 | request.traffic_annotation = |
| 7868 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7869 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7870 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7871 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7872 | |
| 7873 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7874 | MockWrite( |
| 7875 | "GET / HTTP/1.1\r\n" |
| 7876 | "Host: www.example.org\r\n" |
| 7877 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7878 | }; |
| 7879 | |
| 7880 | MockRead data_reads1[] = { |
| 7881 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7882 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7883 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7884 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7885 | }; |
| 7886 | |
| 7887 | // After the challenge above, the transaction will be restarted using the |
| 7888 | // identity supplied by the user, not the one in the URL, to answer the |
| 7889 | // challenge. |
| 7890 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7891 | MockWrite( |
| 7892 | "GET / HTTP/1.1\r\n" |
| 7893 | "Host: www.example.org\r\n" |
| 7894 | "Connection: keep-alive\r\n" |
| 7895 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7896 | }; |
| 7897 | |
| 7898 | MockRead data_reads3[] = { |
| 7899 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7900 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7901 | MockRead(SYNCHRONOUS, OK), |
| 7902 | }; |
| 7903 | |
| 7904 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7905 | data_writes1, arraysize(data_writes1)); |
| 7906 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7907 | data_writes3, arraysize(data_writes3)); |
| 7908 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7909 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7910 | |
| 7911 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7912 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7914 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7915 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7916 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7917 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7918 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7919 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7920 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7921 | |
| 7922 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7923 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7924 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7925 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7926 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7927 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7928 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7929 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7930 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7931 | |
| 7932 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7933 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7934 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7935 | |
| 7936 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7937 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7938 | } |
| 7939 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7940 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7941 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7942 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7943 | |
| 7944 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7945 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7946 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7947 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7948 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7949 | request.traffic_annotation = |
| 7950 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7951 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7952 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7953 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7954 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7955 | MockWrite( |
| 7956 | "GET /x/y/z HTTP/1.1\r\n" |
| 7957 | "Host: www.example.org\r\n" |
| 7958 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7959 | }; |
| 7960 | |
| 7961 | MockRead data_reads1[] = { |
| 7962 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7963 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7964 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7965 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7966 | }; |
| 7967 | |
| 7968 | // Resend with authorization (username=foo, password=bar) |
| 7969 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7970 | MockWrite( |
| 7971 | "GET /x/y/z HTTP/1.1\r\n" |
| 7972 | "Host: www.example.org\r\n" |
| 7973 | "Connection: keep-alive\r\n" |
| 7974 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7975 | }; |
| 7976 | |
| 7977 | // Sever accepts the authorization. |
| 7978 | MockRead data_reads2[] = { |
| 7979 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7980 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7981 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7982 | }; |
| 7983 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7984 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7985 | data_writes1, arraysize(data_writes1)); |
| 7986 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7987 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7988 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7989 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7991 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7992 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7993 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7995 | |
| 7996 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7997 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7998 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7999 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8000 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8001 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8002 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8003 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8004 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8005 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8006 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8007 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8008 | |
| 8009 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8010 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8012 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8013 | ASSERT_TRUE(response); |
| 8014 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8015 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8016 | } |
| 8017 | |
| 8018 | // ------------------------------------------------------------------------ |
| 8019 | |
| 8020 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8021 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8022 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8023 | request.method = "GET"; |
| 8024 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8025 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8026 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8027 | request.traffic_annotation = |
| 8028 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8029 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8030 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8031 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8032 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8033 | MockWrite( |
| 8034 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8035 | "Host: www.example.org\r\n" |
| 8036 | "Connection: keep-alive\r\n" |
| 8037 | // Send preemptive authorization for MyRealm1 |
| 8038 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8039 | }; |
| 8040 | |
| 8041 | // The server didn't like the preemptive authorization, and |
| 8042 | // challenges us for a different realm (MyRealm2). |
| 8043 | MockRead data_reads1[] = { |
| 8044 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8045 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8046 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8047 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8048 | }; |
| 8049 | |
| 8050 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8051 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8052 | MockWrite( |
| 8053 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8054 | "Host: www.example.org\r\n" |
| 8055 | "Connection: keep-alive\r\n" |
| 8056 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8057 | }; |
| 8058 | |
| 8059 | // Sever accepts the authorization. |
| 8060 | MockRead data_reads2[] = { |
| 8061 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8062 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8063 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8064 | }; |
| 8065 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8066 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8067 | data_writes1, arraysize(data_writes1)); |
| 8068 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8069 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8070 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8071 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8073 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8074 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8075 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8076 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8077 | |
| 8078 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8079 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8080 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8081 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8082 | ASSERT_TRUE(response); |
| 8083 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8084 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8085 | EXPECT_EQ("http://www.example.org", |
| 8086 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8087 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8088 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8089 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8090 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8091 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8092 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8093 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8094 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8095 | |
| 8096 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8097 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8098 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8099 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8100 | ASSERT_TRUE(response); |
| 8101 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8102 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8103 | } |
| 8104 | |
| 8105 | // ------------------------------------------------------------------------ |
| 8106 | |
| 8107 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8108 | // succeed with preemptive authorization. |
| 8109 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8110 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8111 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8112 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8113 | request.traffic_annotation = |
| 8114 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8116 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8117 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8118 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8119 | MockWrite( |
| 8120 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8121 | "Host: www.example.org\r\n" |
| 8122 | "Connection: keep-alive\r\n" |
| 8123 | // The authorization for MyRealm1 gets sent preemptively |
| 8124 | // (since the url is in the same protection space) |
| 8125 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8126 | }; |
| 8127 | |
| 8128 | // Sever accepts the preemptive authorization |
| 8129 | MockRead data_reads1[] = { |
| 8130 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8131 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8132 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8133 | }; |
| 8134 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8135 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8136 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8137 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8138 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8139 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8140 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8141 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8142 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8143 | |
| 8144 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8145 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8147 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8148 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8149 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8150 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8151 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8152 | } |
| 8153 | |
| 8154 | // ------------------------------------------------------------------------ |
| 8155 | |
| 8156 | // Transaction 4: request another URL in MyRealm (however the |
| 8157 | // url is not known to belong to the protection space, so no pre-auth). |
| 8158 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8159 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8160 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8161 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8162 | request.traffic_annotation = |
| 8163 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8164 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8165 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8166 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8167 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8168 | MockWrite( |
| 8169 | "GET /x/1 HTTP/1.1\r\n" |
| 8170 | "Host: www.example.org\r\n" |
| 8171 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8172 | }; |
| 8173 | |
| 8174 | MockRead data_reads1[] = { |
| 8175 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8176 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8177 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8178 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8179 | }; |
| 8180 | |
| 8181 | // Resend with authorization from MyRealm's cache. |
| 8182 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8183 | MockWrite( |
| 8184 | "GET /x/1 HTTP/1.1\r\n" |
| 8185 | "Host: www.example.org\r\n" |
| 8186 | "Connection: keep-alive\r\n" |
| 8187 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8188 | }; |
| 8189 | |
| 8190 | // Sever accepts the authorization. |
| 8191 | MockRead data_reads2[] = { |
| 8192 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8193 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8194 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8195 | }; |
| 8196 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8197 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8198 | data_writes1, arraysize(data_writes1)); |
| 8199 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8200 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8201 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8202 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8203 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8204 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8205 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8206 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8207 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8208 | |
| 8209 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8210 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8211 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8212 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8213 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8214 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8215 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8216 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8217 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8218 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8220 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8221 | ASSERT_TRUE(response); |
| 8222 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8223 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8224 | } |
| 8225 | |
| 8226 | // ------------------------------------------------------------------------ |
| 8227 | |
| 8228 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 8229 | // cached identity. Should invalidate and re-prompt. |
| 8230 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8231 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8232 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8233 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8234 | request.traffic_annotation = |
| 8235 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8236 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8237 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8238 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8239 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8240 | MockWrite( |
| 8241 | "GET /p/q/t HTTP/1.1\r\n" |
| 8242 | "Host: www.example.org\r\n" |
| 8243 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8244 | }; |
| 8245 | |
| 8246 | MockRead data_reads1[] = { |
| 8247 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8248 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8249 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8250 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8251 | }; |
| 8252 | |
| 8253 | // Resend with authorization from cache for MyRealm. |
| 8254 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8255 | MockWrite( |
| 8256 | "GET /p/q/t HTTP/1.1\r\n" |
| 8257 | "Host: www.example.org\r\n" |
| 8258 | "Connection: keep-alive\r\n" |
| 8259 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8260 | }; |
| 8261 | |
| 8262 | // Sever rejects the authorization. |
| 8263 | MockRead data_reads2[] = { |
| 8264 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8265 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8266 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8267 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8268 | }; |
| 8269 | |
| 8270 | // At this point we should prompt for new credentials for MyRealm. |
| 8271 | // Restart with username=foo3, password=foo4. |
| 8272 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8273 | MockWrite( |
| 8274 | "GET /p/q/t HTTP/1.1\r\n" |
| 8275 | "Host: www.example.org\r\n" |
| 8276 | "Connection: keep-alive\r\n" |
| 8277 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8278 | }; |
| 8279 | |
| 8280 | // Sever accepts the authorization. |
| 8281 | MockRead data_reads3[] = { |
| 8282 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8283 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8284 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8285 | }; |
| 8286 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8287 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8288 | data_writes1, arraysize(data_writes1)); |
| 8289 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8290 | data_writes2, arraysize(data_writes2)); |
| 8291 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8292 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8293 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8294 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8295 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8296 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8297 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8298 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8299 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8300 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8301 | |
| 8302 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8303 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8304 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8305 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8306 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8307 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8308 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8309 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8310 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8311 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8313 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8314 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8315 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8316 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8317 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8318 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8319 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 8320 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8321 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8322 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8323 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8324 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8325 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8326 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8327 | ASSERT_TRUE(response); |
| 8328 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8329 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8330 | } |
| 8331 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8332 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8333 | // Tests that nonce count increments when multiple auth attempts |
| 8334 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8335 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 8336 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 8337 | new HttpAuthHandlerDigest::Factory(); |
| 8338 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 8339 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 8340 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8341 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8342 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8343 | |
| 8344 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8345 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8346 | HttpRequestInfo request; |
| 8347 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8348 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8349 | request.traffic_annotation = |
| 8350 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8351 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8352 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8353 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8354 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8355 | MockWrite( |
| 8356 | "GET /x/y/z HTTP/1.1\r\n" |
| 8357 | "Host: www.example.org\r\n" |
| 8358 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8359 | }; |
| 8360 | |
| 8361 | MockRead data_reads1[] = { |
| 8362 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8363 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 8364 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8365 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8366 | }; |
| 8367 | |
| 8368 | // Resend with authorization (username=foo, password=bar) |
| 8369 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8370 | MockWrite( |
| 8371 | "GET /x/y/z HTTP/1.1\r\n" |
| 8372 | "Host: www.example.org\r\n" |
| 8373 | "Connection: keep-alive\r\n" |
| 8374 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8375 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 8376 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 8377 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8378 | }; |
| 8379 | |
| 8380 | // Sever accepts the authorization. |
| 8381 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8382 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8383 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8384 | }; |
| 8385 | |
| 8386 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8387 | data_writes1, arraysize(data_writes1)); |
| 8388 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8389 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8390 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8391 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8392 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8393 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8394 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8395 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8396 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8397 | |
| 8398 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8399 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8400 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8401 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8402 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8403 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8405 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8407 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8408 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8409 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8410 | |
| 8411 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8412 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8413 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8414 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8415 | ASSERT_TRUE(response); |
| 8416 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8417 | } |
| 8418 | |
| 8419 | // ------------------------------------------------------------------------ |
| 8420 | |
| 8421 | // Transaction 2: Request another resource in digestive's protection space. |
| 8422 | // This will preemptively add an Authorization header which should have an |
| 8423 | // "nc" value of 2 (as compared to 1 in the first use. |
| 8424 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8425 | HttpRequestInfo request; |
| 8426 | request.method = "GET"; |
| 8427 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8428 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8429 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8430 | request.traffic_annotation = |
| 8431 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8432 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8433 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8434 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8435 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8436 | MockWrite( |
| 8437 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8438 | "Host: www.example.org\r\n" |
| 8439 | "Connection: keep-alive\r\n" |
| 8440 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8441 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 8442 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 8443 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8444 | }; |
| 8445 | |
| 8446 | // Sever accepts the authorization. |
| 8447 | MockRead data_reads1[] = { |
| 8448 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8449 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8450 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8451 | }; |
| 8452 | |
| 8453 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8454 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8455 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8456 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8457 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8458 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8459 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8460 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8461 | |
| 8462 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8463 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8464 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8465 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8466 | ASSERT_TRUE(response); |
| 8467 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8468 | } |
| 8469 | } |
| 8470 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8471 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8472 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8473 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8474 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8475 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8476 | |
| 8477 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8478 | trans.read_buf_ = new IOBuffer(15); |
| 8479 | trans.read_buf_len_ = 15; |
| 8480 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8481 | |
| 8482 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8483 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8484 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8485 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8486 | response->response_time = base::Time::Now(); |
| 8487 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8488 | |
| 8489 | { // Setup state for response_.vary_data |
| 8490 | HttpRequestInfo request; |
| 8491 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 8492 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 8493 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8494 | request.extra_headers.SetHeader("Foo", "1"); |
| 8495 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8496 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8497 | } |
| 8498 | |
| 8499 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8500 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8501 | |
| 8502 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8503 | EXPECT_FALSE(trans.read_buf_); |
| 8504 | EXPECT_EQ(0, trans.read_buf_len_); |
| 8505 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8506 | EXPECT_FALSE(response->auth_challenge); |
| 8507 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 8508 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8509 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8510 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8511 | } |
| 8512 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8513 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8514 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8515 | HttpRequestInfo request; |
| 8516 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8517 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8518 | request.traffic_annotation = |
| 8519 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8520 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8521 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8522 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8523 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8524 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8525 | MockWrite( |
| 8526 | "GET / HTTP/1.1\r\n" |
| 8527 | "Host: www.example.org\r\n" |
| 8528 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8529 | }; |
| 8530 | |
| 8531 | MockRead data_reads[] = { |
| 8532 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8533 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8534 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8535 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8536 | }; |
| 8537 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 8538 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8539 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8540 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8541 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8542 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8543 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8544 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8545 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8546 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8547 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8548 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8549 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8550 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8551 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8552 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8553 | |
| 8554 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8555 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8556 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8557 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8558 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8559 | |
| 8560 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8561 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8562 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8563 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8564 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8565 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8566 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8567 | } |
| 8568 | |
| 8569 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 8570 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8571 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8572 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8573 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8574 | |
| 8575 | HttpRequestInfo request; |
| 8576 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8577 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8578 | request.traffic_annotation = |
| 8579 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8580 | |
| 8581 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8582 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8583 | "Host: www.example.org:443\r\n" |
| 8584 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8585 | }; |
| 8586 | |
| 8587 | MockRead proxy_reads[] = { |
| 8588 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8589 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8590 | }; |
| 8591 | |
| 8592 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8593 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8594 | "Host: www.example.org:443\r\n" |
| 8595 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8596 | MockWrite("GET / HTTP/1.1\r\n" |
| 8597 | "Host: www.example.org\r\n" |
| 8598 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8599 | }; |
| 8600 | |
| 8601 | MockRead data_reads[] = { |
| 8602 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8603 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8604 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8605 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8606 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8607 | }; |
| 8608 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8609 | StaticSocketDataProvider ssl_bad_certificate( |
| 8610 | proxy_reads, arraysize(proxy_reads), |
| 8611 | proxy_writes, arraysize(proxy_writes)); |
| 8612 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8613 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8614 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8615 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8616 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8617 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8618 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8621 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8622 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8623 | |
| 8624 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8625 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8626 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8627 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8628 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8629 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8630 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8632 | |
| 8633 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8634 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8635 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8636 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8638 | |
| 8639 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8640 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8641 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8642 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8643 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8644 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8645 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8646 | } |
| 8647 | } |
| 8648 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8649 | |
| 8650 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8651 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8652 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8653 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8654 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8655 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8656 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8657 | |
| 8658 | HttpRequestInfo request; |
| 8659 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8660 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8661 | request.traffic_annotation = |
| 8662 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8663 | |
| 8664 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8665 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8666 | "Host: www.example.org:443\r\n" |
| 8667 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8668 | MockWrite("GET / HTTP/1.1\r\n" |
| 8669 | "Host: www.example.org\r\n" |
| 8670 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8671 | }; |
| 8672 | |
| 8673 | MockRead data_reads[] = { |
| 8674 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8675 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8676 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8677 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8678 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8679 | }; |
| 8680 | |
| 8681 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8682 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8683 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8684 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8685 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8686 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8687 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8688 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8689 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8690 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8691 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8692 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8693 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8694 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8695 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8697 | |
| 8698 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8699 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8700 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8701 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8702 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8703 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8704 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8705 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8706 | EXPECT_EQ(200, response->headers->response_code()); |
| 8707 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8708 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8709 | |
| 8710 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8711 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8712 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8713 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8714 | } |
| 8715 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8716 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8717 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8718 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8719 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8720 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8721 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8722 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8723 | |
| 8724 | HttpRequestInfo request; |
| 8725 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8726 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8727 | request.traffic_annotation = |
| 8728 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8729 | |
| 8730 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8731 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8732 | "Host: www.example.org:443\r\n" |
| 8733 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8734 | }; |
| 8735 | |
| 8736 | MockRead data_reads[] = { |
| 8737 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8738 | MockRead("Location: http://login.example.com/\r\n"), |
| 8739 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8740 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8741 | }; |
| 8742 | |
| 8743 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8744 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8745 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8746 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8747 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8748 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8749 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8750 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8751 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8753 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8754 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8755 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8757 | |
| 8758 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8759 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8760 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8761 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8762 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8763 | |
| 8764 | EXPECT_EQ(302, response->headers->response_code()); |
| 8765 | std::string url; |
| 8766 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8767 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8768 | |
| 8769 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8770 | // timing for the proxy connection instead of the connection to the host, |
| 8771 | // and no send / receive times. |
| 8772 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8773 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8774 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8775 | |
| 8776 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8777 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8778 | |
| 8779 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8780 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8781 | load_timing_info.proxy_resolve_end); |
| 8782 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8783 | load_timing_info.connect_timing.connect_start); |
| 8784 | ExpectConnectTimingHasTimes( |
| 8785 | load_timing_info.connect_timing, |
| 8786 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8787 | |
| 8788 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8789 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8790 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8791 | } |
| 8792 | |
| 8793 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8794 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8795 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8796 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8797 | |
| 8798 | HttpRequestInfo request; |
| 8799 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8800 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8801 | request.traffic_annotation = |
| 8802 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8803 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8804 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8805 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8806 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8807 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8808 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8809 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8810 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8811 | }; |
| 8812 | |
| 8813 | static const char* const kExtraHeaders[] = { |
| 8814 | "location", |
| 8815 | "http://login.example.com/", |
| 8816 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8817 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8818 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8819 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8820 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8821 | }; |
| 8822 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8823 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8824 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8825 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8826 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8827 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8828 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8829 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8831 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8832 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8833 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8834 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8835 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8836 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8837 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8838 | |
| 8839 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8840 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8841 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8842 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8843 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8844 | |
| 8845 | EXPECT_EQ(302, response->headers->response_code()); |
| 8846 | std::string url; |
| 8847 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8848 | EXPECT_EQ("http://login.example.com/", url); |
| 8849 | } |
| 8850 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8851 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8852 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8853 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8854 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8855 | |
| 8856 | HttpRequestInfo request; |
| 8857 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8858 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8859 | request.traffic_annotation = |
| 8860 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8861 | |
| 8862 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8863 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8864 | "Host: www.example.org:443\r\n" |
| 8865 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8866 | }; |
| 8867 | |
| 8868 | MockRead data_reads[] = { |
| 8869 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8870 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8871 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8872 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8873 | }; |
| 8874 | |
| 8875 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8876 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8877 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8878 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8879 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8880 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8881 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8882 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8883 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8884 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8885 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8886 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8887 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8888 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8889 | |
| 8890 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8891 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8892 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8893 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8894 | } |
| 8895 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8896 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8897 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8898 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8899 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8900 | |
| 8901 | HttpRequestInfo request; |
| 8902 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8903 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8904 | request.traffic_annotation = |
| 8905 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8906 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8907 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8908 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8909 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8910 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8911 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8912 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8913 | }; |
| 8914 | |
| 8915 | static const char* const kExtraHeaders[] = { |
| 8916 | "location", |
| 8917 | "http://login.example.com/", |
| 8918 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8919 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8920 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8921 | SpdySerializedFrame body( |
| 8922 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8923 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8924 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8925 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8926 | }; |
| 8927 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8928 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8929 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8930 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8931 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8932 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8933 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8934 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8935 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8936 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8937 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8938 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8939 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8940 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8941 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8942 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8943 | |
| 8944 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8945 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8946 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8947 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8948 | } |
| 8949 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8950 | // Test the request-challenge-retry sequence for basic auth, through |
| 8951 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8952 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8953 | HttpRequestInfo request; |
| 8954 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8955 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8956 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8957 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8958 | request.traffic_annotation = |
| 8959 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8960 | |
| 8961 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8962 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8963 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8964 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8965 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8966 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8967 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8968 | |
| 8969 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8970 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8971 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8972 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8973 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8974 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8975 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8976 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8977 | // be issuing -- the final header line contains the credentials. |
| 8978 | const char* const kAuthCredentials[] = { |
| 8979 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8980 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8981 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8982 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8983 | HostPortPair("www.example.org", 443))); |
| 8984 | // fetch https://www.example.org/ via HTTP |
| 8985 | const char get[] = |
| 8986 | "GET / HTTP/1.1\r\n" |
| 8987 | "Host: www.example.org\r\n" |
| 8988 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8989 | SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8990 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8991 | |
| 8992 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8993 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8994 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8995 | }; |
| 8996 | |
| 8997 | // The proxy responds to the connect with a 407, using a persistent |
| 8998 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8999 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9000 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9001 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9002 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9003 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9004 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9005 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9006 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9007 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 9008 | "Content-Length: 5\r\n\r\n"; |
| 9009 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9010 | SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9011 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9012 | SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9013 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9014 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9015 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 9016 | CreateMockRead(conn_resp, 4, ASYNC), |
| 9017 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 9018 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9019 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9020 | }; |
| 9021 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9022 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9023 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9024 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9025 | // Negotiate SPDY to the proxy |
| 9026 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9027 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9028 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9029 | // Vanilla SSL to the server |
| 9030 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9031 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9032 | |
| 9033 | TestCompletionCallback callback1; |
| 9034 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9035 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9036 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9037 | |
| 9038 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9039 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9040 | |
| 9041 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9042 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 9043 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9044 | log.GetEntries(&entries); |
| 9045 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9046 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 9047 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9048 | ExpectLogContainsSomewhere( |
| 9049 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9050 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9051 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9052 | |
| 9053 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9054 | ASSERT_TRUE(response); |
| 9055 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9056 | EXPECT_EQ(407, response->headers->response_code()); |
| 9057 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9058 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9059 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9060 | |
| 9061 | TestCompletionCallback callback2; |
| 9062 | |
| 9063 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9064 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9066 | |
| 9067 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9068 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9069 | |
| 9070 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9071 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9072 | |
| 9073 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9074 | EXPECT_EQ(200, response->headers->response_code()); |
| 9075 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 9076 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9077 | |
| 9078 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9079 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9080 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9081 | LoadTimingInfo load_timing_info; |
| 9082 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9083 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9084 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9085 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9086 | trans.reset(); |
| 9087 | session->CloseAllConnections(); |
| 9088 | } |
| 9089 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9090 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 9091 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9092 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9093 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9094 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9095 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9096 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9097 | HttpRequestInfo request; |
| 9098 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9099 | request.traffic_annotation = |
| 9100 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9101 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9102 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9103 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9104 | push_request.method = "GET"; |
| 9105 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9106 | push_request.traffic_annotation = |
| 9107 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9108 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9109 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9110 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9111 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9112 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9113 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9114 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9115 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9116 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9117 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9119 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9120 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9121 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9122 | SpdySerializedFrame stream2_priority( |
| 9123 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9124 | |
| 9125 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9126 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9127 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9128 | }; |
| 9129 | |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9130 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
| 9131 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 9132 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9133 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9134 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9135 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9136 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9137 | |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9138 | SpdySerializedFrame stream2_body( |
| 9139 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9140 | |
| 9141 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9142 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 9143 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9144 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9145 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9146 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9147 | }; |
| 9148 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9149 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9150 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9151 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9152 | // Negotiate SPDY to the proxy |
| 9153 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9154 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9155 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9156 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9157 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9158 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9159 | TestCompletionCallback callback; |
| 9160 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9161 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9162 | |
| 9163 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9164 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9165 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9166 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9167 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9168 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9169 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9170 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9171 | |
| 9172 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9173 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9174 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 9175 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9176 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9177 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9178 | |
| 9179 | EXPECT_EQ(200, response->headers->response_code()); |
| 9180 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9181 | |
| 9182 | std::string response_data; |
| 9183 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9184 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9185 | EXPECT_EQ("hello!", response_data); |
| 9186 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9187 | LoadTimingInfo load_timing_info; |
| 9188 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9189 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9190 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9191 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9192 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9193 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9194 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 9195 | |
| 9196 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9197 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9198 | EXPECT_EQ("pushed", response_data); |
| 9199 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9200 | LoadTimingInfo push_load_timing_info; |
| 9201 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 9202 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 9203 | // The transactions should share a socket ID, despite being for different |
| 9204 | // origins. |
| 9205 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 9206 | push_load_timing_info.socket_log_id); |
| 9207 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9208 | trans.reset(); |
| 9209 | push_trans.reset(); |
| 9210 | session->CloseAllConnections(); |
| 9211 | } |
| 9212 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9213 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9214 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9215 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9216 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9217 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9218 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9219 | HttpRequestInfo request; |
| 9220 | |
| 9221 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9222 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9223 | request.traffic_annotation = |
| 9224 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9225 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9226 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9227 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9228 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9229 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9230 | |
| 9231 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9232 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9233 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9234 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9235 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9236 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9237 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9238 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9239 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 9240 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9241 | |
| 9242 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9243 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9244 | }; |
| 9245 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9246 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9247 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9248 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9249 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9250 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9251 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 9252 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9253 | |
| 9254 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9255 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9256 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 9257 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 9258 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9259 | }; |
| 9260 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9261 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9262 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9263 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9264 | // Negotiate SPDY to the proxy |
| 9265 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9266 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9267 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9268 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9269 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9270 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9271 | TestCompletionCallback callback; |
| 9272 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9273 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9274 | |
| 9275 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9276 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9277 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9278 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9279 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9280 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9281 | |
| 9282 | EXPECT_EQ(200, response->headers->response_code()); |
| 9283 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9284 | |
| 9285 | std::string response_data; |
| 9286 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9287 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9288 | EXPECT_EQ("hello!", response_data); |
| 9289 | |
| 9290 | trans.reset(); |
| 9291 | session->CloseAllConnections(); |
| 9292 | } |
| 9293 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9294 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 9295 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9296 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9297 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9298 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9299 | proxy_delegate->set_trusted_spdy_proxy( |
| 9300 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 9301 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9302 | HttpRequestInfo request; |
| 9303 | |
| 9304 | request.method = "GET"; |
| 9305 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9306 | request.traffic_annotation = |
| 9307 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9308 | |
| 9309 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9310 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9311 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9312 | BoundTestNetLog log; |
| 9313 | session_deps_.net_log = log.bound().net_log(); |
| 9314 | |
| 9315 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9316 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9317 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9318 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9319 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9320 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9321 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9322 | SpdySerializedFrame stream2_priority( |
| 9323 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9324 | |
| 9325 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9326 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9327 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9328 | }; |
| 9329 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9330 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9331 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9332 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9333 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 9334 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 9335 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9336 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9337 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9338 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9339 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9340 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9341 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9342 | |
| 9343 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9344 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9345 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9346 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9347 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9348 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9349 | }; |
| 9350 | |
| 9351 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9352 | arraysize(spdy_writes)); |
| 9353 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 9354 | // Negotiate SPDY to the proxy |
| 9355 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9356 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9357 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 9358 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9359 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9360 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9361 | TestCompletionCallback callback; |
| 9362 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9363 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9364 | |
| 9365 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9366 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9367 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9368 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9369 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9370 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9371 | |
| 9372 | EXPECT_EQ(200, response->headers->response_code()); |
| 9373 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9374 | |
| 9375 | std::string response_data; |
| 9376 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9377 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9378 | EXPECT_EQ("hello!", response_data); |
| 9379 | |
| 9380 | trans.reset(); |
| 9381 | session->CloseAllConnections(); |
| 9382 | } |
| 9383 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9384 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 9385 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9386 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9387 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9388 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9389 | |
| 9390 | HttpRequestInfo request; |
| 9391 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9392 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9393 | request.traffic_annotation = |
| 9394 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9395 | |
| 9396 | // Attempt to fetch the URL from a server with a bad cert |
| 9397 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9398 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9399 | "Host: www.example.org:443\r\n" |
| 9400 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9401 | }; |
| 9402 | |
| 9403 | MockRead bad_cert_reads[] = { |
| 9404 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9405 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9406 | }; |
| 9407 | |
| 9408 | // Attempt to fetch the URL with a good cert |
| 9409 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9410 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9411 | "Host: www.example.org:443\r\n" |
| 9412 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9413 | MockWrite("GET / HTTP/1.1\r\n" |
| 9414 | "Host: www.example.org\r\n" |
| 9415 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9416 | }; |
| 9417 | |
| 9418 | MockRead good_cert_reads[] = { |
| 9419 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9420 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9421 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9422 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9423 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9424 | }; |
| 9425 | |
| 9426 | StaticSocketDataProvider ssl_bad_certificate( |
| 9427 | bad_cert_reads, arraysize(bad_cert_reads), |
| 9428 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 9429 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 9430 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9431 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9432 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9433 | |
| 9434 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9435 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9436 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9437 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9438 | |
| 9439 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9440 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9441 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9442 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9443 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9444 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9445 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9446 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9447 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9448 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9449 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9450 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9451 | |
| 9452 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9453 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9454 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9455 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9457 | |
| 9458 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9459 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9460 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9461 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9462 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9463 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9464 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9465 | } |
| 9466 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9467 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9468 | HttpRequestInfo request; |
| 9469 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9470 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9471 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9472 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9473 | request.traffic_annotation = |
| 9474 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9475 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9476 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9477 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9478 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9479 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9480 | MockWrite( |
| 9481 | "GET / HTTP/1.1\r\n" |
| 9482 | "Host: www.example.org\r\n" |
| 9483 | "Connection: keep-alive\r\n" |
| 9484 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9485 | }; |
| 9486 | |
| 9487 | // Lastly, the server responds with the actual content. |
| 9488 | MockRead data_reads[] = { |
| 9489 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9490 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9491 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9492 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9493 | }; |
| 9494 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9495 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9496 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9497 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9498 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9499 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9500 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9501 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9502 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9503 | |
| 9504 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9505 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9506 | } |
| 9507 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9508 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9509 | HttpRequestInfo request; |
| 9510 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9511 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9512 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9513 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9514 | request.traffic_annotation = |
| 9515 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9516 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9517 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9518 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9519 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9520 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9521 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9522 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9523 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9524 | "Host: www.example.org:443\r\n" |
| 9525 | "Proxy-Connection: keep-alive\r\n" |
| 9526 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9527 | }; |
| 9528 | MockRead data_reads[] = { |
| 9529 | // Return an error, so the transaction stops here (this test isn't |
| 9530 | // interested in the rest). |
| 9531 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 9532 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9533 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 9534 | }; |
| 9535 | |
| 9536 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9537 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9538 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9539 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9540 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9541 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9542 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9544 | |
| 9545 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9546 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9547 | } |
| 9548 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9549 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9550 | HttpRequestInfo request; |
| 9551 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9552 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 9553 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 9554 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9555 | request.traffic_annotation = |
| 9556 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9557 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9558 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9559 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9560 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9561 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9562 | MockWrite( |
| 9563 | "GET / HTTP/1.1\r\n" |
| 9564 | "Host: www.example.org\r\n" |
| 9565 | "Connection: keep-alive\r\n" |
| 9566 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9567 | }; |
| 9568 | |
| 9569 | // Lastly, the server responds with the actual content. |
| 9570 | MockRead data_reads[] = { |
| 9571 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9572 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9573 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9574 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9575 | }; |
| 9576 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9577 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9578 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9579 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9580 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9581 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9582 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9583 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9584 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9585 | |
| 9586 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9587 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9588 | } |
| 9589 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9590 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9591 | HttpRequestInfo request; |
| 9592 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9593 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9594 | request.traffic_annotation = |
| 9595 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [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] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9599 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9600 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9601 | MockWrite( |
| 9602 | "POST / HTTP/1.1\r\n" |
| 9603 | "Host: www.example.org\r\n" |
| 9604 | "Connection: keep-alive\r\n" |
| 9605 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9606 | }; |
| 9607 | |
| 9608 | // Lastly, the server responds with the actual content. |
| 9609 | MockRead data_reads[] = { |
| 9610 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9611 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9612 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9613 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9614 | }; |
| 9615 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9616 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9617 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9618 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9619 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9620 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9621 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9622 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9623 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9624 | |
| 9625 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9626 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9627 | } |
| 9628 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9629 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9630 | HttpRequestInfo request; |
| 9631 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9632 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9633 | request.traffic_annotation = |
| 9634 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9635 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9636 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9637 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9638 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9639 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9640 | MockWrite( |
| 9641 | "PUT / HTTP/1.1\r\n" |
| 9642 | "Host: www.example.org\r\n" |
| 9643 | "Connection: keep-alive\r\n" |
| 9644 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9645 | }; |
| 9646 | |
| 9647 | // Lastly, the server responds with the actual content. |
| 9648 | MockRead data_reads[] = { |
| 9649 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9650 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9651 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9652 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9653 | }; |
| 9654 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9655 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9656 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9657 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9658 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9659 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9660 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9661 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9662 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9663 | |
| 9664 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9665 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9666 | } |
| 9667 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9668 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9669 | HttpRequestInfo request; |
| 9670 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9671 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9672 | request.traffic_annotation = |
| 9673 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9674 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9675 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9676 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9677 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9678 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 9679 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 9680 | "Host: www.example.org\r\n" |
| 9681 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9682 | }; |
| 9683 | |
| 9684 | // Lastly, the server responds with the actual content. |
| 9685 | MockRead data_reads[] = { |
| 9686 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9687 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9688 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9689 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9690 | }; |
| 9691 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9692 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9693 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9694 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9695 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9696 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9697 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9698 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9699 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9700 | |
| 9701 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9702 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9703 | } |
| 9704 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9705 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9706 | HttpRequestInfo request; |
| 9707 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9708 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9709 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9710 | request.traffic_annotation = |
| 9711 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9712 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9713 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9714 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9715 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9716 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9717 | MockWrite( |
| 9718 | "GET / HTTP/1.1\r\n" |
| 9719 | "Host: www.example.org\r\n" |
| 9720 | "Connection: keep-alive\r\n" |
| 9721 | "Pragma: no-cache\r\n" |
| 9722 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9723 | }; |
| 9724 | |
| 9725 | // Lastly, the server responds with the actual content. |
| 9726 | MockRead data_reads[] = { |
| 9727 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9728 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9729 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9730 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9731 | }; |
| 9732 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9733 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9734 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9735 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9736 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9737 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9738 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9739 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9741 | |
| 9742 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9743 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9744 | } |
| 9745 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9746 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9747 | HttpRequestInfo request; |
| 9748 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9749 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9750 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9751 | request.traffic_annotation = |
| 9752 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9753 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9754 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9755 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9756 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9757 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9758 | MockWrite( |
| 9759 | "GET / HTTP/1.1\r\n" |
| 9760 | "Host: www.example.org\r\n" |
| 9761 | "Connection: keep-alive\r\n" |
| 9762 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9763 | }; |
| 9764 | |
| 9765 | // Lastly, the server responds with the actual content. |
| 9766 | MockRead data_reads[] = { |
| 9767 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9768 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9769 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9770 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9771 | }; |
| 9772 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9773 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9774 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9775 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9776 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9777 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9778 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9779 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9780 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9781 | |
| 9782 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9783 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9784 | } |
| 9785 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9786 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9787 | HttpRequestInfo request; |
| 9788 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9789 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9790 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9791 | request.traffic_annotation = |
| 9792 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9793 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9794 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9795 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9796 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9797 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9798 | MockWrite( |
| 9799 | "GET / HTTP/1.1\r\n" |
| 9800 | "Host: www.example.org\r\n" |
| 9801 | "Connection: keep-alive\r\n" |
| 9802 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9803 | }; |
| 9804 | |
| 9805 | // Lastly, the server responds with the actual content. |
| 9806 | MockRead data_reads[] = { |
| 9807 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9808 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9809 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9810 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9811 | }; |
| 9812 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9813 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9814 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9815 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9817 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9818 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9819 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9821 | |
| 9822 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9823 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9824 | } |
| 9825 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9826 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9827 | HttpRequestInfo request; |
| 9828 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9829 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9830 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9831 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9832 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9833 | request.traffic_annotation = |
| 9834 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9835 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9836 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9837 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9838 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9839 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9840 | MockWrite( |
| 9841 | "GET / HTTP/1.1\r\n" |
| 9842 | "Host: www.example.org\r\n" |
| 9843 | "Connection: keep-alive\r\n" |
| 9844 | "referer: www.foo.com\r\n" |
| 9845 | "hEllo: Kitty\r\n" |
| 9846 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9847 | }; |
| 9848 | |
| 9849 | // Lastly, the server responds with the actual content. |
| 9850 | MockRead data_reads[] = { |
| 9851 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9852 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9853 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9854 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9855 | }; |
| 9856 | |
| 9857 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9858 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9859 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9860 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9861 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9862 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9863 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9864 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9865 | |
| 9866 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9867 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9868 | } |
| 9869 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9870 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9871 | HttpRequestInfo request; |
| 9872 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9873 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9874 | request.traffic_annotation = |
| 9875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9876 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9877 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9878 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9879 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9880 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9881 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9882 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9883 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9884 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9885 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9886 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9887 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9888 | |
| 9889 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9890 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9891 | MockWrite( |
| 9892 | "GET / HTTP/1.1\r\n" |
| 9893 | "Host: www.example.org\r\n" |
| 9894 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9895 | |
| 9896 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9897 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9898 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9899 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9900 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9901 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9902 | }; |
| 9903 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9904 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9905 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9906 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9907 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9908 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9909 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9910 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9911 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9912 | |
| 9913 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9914 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9916 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9917 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9918 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9919 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9920 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9921 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9922 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9923 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9924 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9925 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9926 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9927 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9928 | EXPECT_EQ("Payload", response_text); |
| 9929 | } |
| 9930 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9931 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9932 | HttpRequestInfo request; |
| 9933 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9934 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9935 | request.traffic_annotation = |
| 9936 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9937 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9938 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9939 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9940 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9941 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9942 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9943 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9944 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9945 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9946 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9947 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9948 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9949 | |
| 9950 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9951 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9952 | arraysize(write_buffer)), |
| 9953 | MockWrite( |
| 9954 | "GET / HTTP/1.1\r\n" |
| 9955 | "Host: www.example.org\r\n" |
| 9956 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9957 | |
| 9958 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9959 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9960 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9961 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9962 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9963 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9964 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9965 | }; |
| 9966 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9967 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9968 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9969 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9970 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9971 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9972 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9973 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9974 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9975 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9976 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9977 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9978 | |
| 9979 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9980 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9981 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9982 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9983 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9984 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9985 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9986 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9987 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9988 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9989 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9990 | |
| 9991 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9992 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9993 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9994 | EXPECT_EQ("Payload", response_text); |
| 9995 | } |
| 9996 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9997 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9998 | HttpRequestInfo request; |
| 9999 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10000 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10001 | request.traffic_annotation = |
| 10002 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10003 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10004 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10005 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10006 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10007 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10008 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10009 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10010 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10011 | |
| 10012 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10013 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10014 | |
| 10015 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10016 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 10017 | MockWrite( |
| 10018 | "GET / HTTP/1.1\r\n" |
| 10019 | "Host: www.example.org\r\n" |
| 10020 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10021 | |
| 10022 | MockRead data_reads[] = { |
| 10023 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 10024 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10025 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10026 | MockRead("Payload"), |
| 10027 | MockRead(SYNCHRONOUS, OK) |
| 10028 | }; |
| 10029 | |
| 10030 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10031 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10032 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10033 | |
| 10034 | TestCompletionCallback callback; |
| 10035 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10036 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10037 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10038 | |
| 10039 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10040 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10041 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10042 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10043 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10044 | |
| 10045 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10046 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10047 | TestLoadTimingNotReused(load_timing_info, |
| 10048 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10049 | |
| 10050 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10051 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10052 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10053 | EXPECT_EQ("Payload", response_text); |
| 10054 | } |
| 10055 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10056 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10057 | HttpRequestInfo request; |
| 10058 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10059 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10060 | request.traffic_annotation = |
| 10061 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10062 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10063 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10064 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10065 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10066 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10067 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10068 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10069 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10070 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10071 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10072 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10073 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10074 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10075 | 0x05, // Version |
| 10076 | 0x01, // Command (CONNECT) |
| 10077 | 0x00, // Reserved. |
| 10078 | 0x03, // Address type (DOMAINNAME). |
| 10079 | 0x0F, // Length of domain (15) |
| 10080 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10081 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10082 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10083 | const char kSOCKS5OkResponse[] = |
| 10084 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 10085 | |
| 10086 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10087 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10088 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 10089 | MockWrite( |
| 10090 | "GET / HTTP/1.1\r\n" |
| 10091 | "Host: www.example.org\r\n" |
| 10092 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10093 | |
| 10094 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10095 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10096 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10097 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10098 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10099 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10100 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10101 | }; |
| 10102 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10103 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10104 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10105 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10106 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10107 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10108 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10109 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10110 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10111 | |
| 10112 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10113 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10114 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10115 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10116 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10117 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10118 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10119 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10120 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10121 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10122 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10123 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10124 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10125 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10126 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10127 | EXPECT_EQ("Payload", response_text); |
| 10128 | } |
| 10129 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10130 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10131 | HttpRequestInfo request; |
| 10132 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10133 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10134 | request.traffic_annotation = |
| 10135 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10136 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10137 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10138 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10139 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10140 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10141 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10142 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10143 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10144 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10145 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10146 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10147 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10148 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10149 | 0x05, // Version |
| 10150 | 0x01, // Command (CONNECT) |
| 10151 | 0x00, // Reserved. |
| 10152 | 0x03, // Address type (DOMAINNAME). |
| 10153 | 0x0F, // Length of domain (15) |
| 10154 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10155 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10156 | }; |
| 10157 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10158 | const char kSOCKS5OkResponse[] = |
| 10159 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 10160 | |
| 10161 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10162 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10163 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 10164 | arraysize(kSOCKS5OkRequest)), |
| 10165 | MockWrite( |
| 10166 | "GET / HTTP/1.1\r\n" |
| 10167 | "Host: www.example.org\r\n" |
| 10168 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10169 | |
| 10170 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10171 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10172 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10173 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10174 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10175 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10176 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10177 | }; |
| 10178 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10179 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10180 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10181 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10182 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10183 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10184 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10185 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10186 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10187 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10188 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10189 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10190 | |
| 10191 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10192 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10193 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10194 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10195 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10196 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10197 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10198 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10199 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10200 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10201 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10202 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10203 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10204 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10205 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10206 | EXPECT_EQ("Payload", response_text); |
| 10207 | } |
| 10208 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10209 | namespace { |
| 10210 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10211 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10212 | |
| 10213 | struct GroupNameTest { |
| 10214 | std::string proxy_server; |
| 10215 | std::string url; |
| 10216 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10217 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10218 | }; |
| 10219 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10220 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10221 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10223 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10224 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10225 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10226 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10227 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10228 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10229 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10230 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10231 | |
| 10232 | return session; |
| 10233 | } |
| 10234 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10235 | int GroupNameTransactionHelper(const std::string& url, |
| 10236 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10237 | HttpRequestInfo request; |
| 10238 | request.method = "GET"; |
| 10239 | request.url = GURL(url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10240 | request.traffic_annotation = |
| 10241 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10242 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10243 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10245 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10246 | |
| 10247 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10248 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10249 | } |
| 10250 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10251 | } // namespace |
| 10252 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10253 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10254 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10255 | { |
| 10256 | "", // unused |
| 10257 | "http://www.example.org/direct", |
| 10258 | "www.example.org:80", |
| 10259 | false, |
| 10260 | }, |
| 10261 | { |
| 10262 | "", // unused |
| 10263 | "http://[2001:1418:13:1::25]/direct", |
| 10264 | "[2001:1418:13:1::25]:80", |
| 10265 | false, |
| 10266 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10267 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10268 | // SSL Tests |
| 10269 | { |
| 10270 | "", // unused |
| 10271 | "https://www.example.org/direct_ssl", |
| 10272 | "ssl/www.example.org:443", |
| 10273 | true, |
| 10274 | }, |
| 10275 | { |
| 10276 | "", // unused |
| 10277 | "https://[2001:1418:13:1::25]/direct", |
| 10278 | "ssl/[2001:1418:13:1::25]:443", |
| 10279 | true, |
| 10280 | }, |
| 10281 | { |
| 10282 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10283 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10284 | "ssl/host.with.alternate:443", |
| 10285 | true, |
| 10286 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10287 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10288 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10289 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10290 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10291 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10292 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10293 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10294 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10295 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10296 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10297 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10298 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10299 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10300 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10301 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10302 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 10303 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10304 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10305 | |
| 10306 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10307 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10308 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10309 | EXPECT_EQ(tests[i].expected_group_name, |
| 10310 | ssl_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10311 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10312 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10313 | transport_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10314 | } |
| 10315 | // When SSL proxy is in use, socket must be requested from |ssl_conn_pool|. |
| 10316 | EXPECT_EQ(tests[i].ssl, ssl_conn_pool->socket_requested()); |
| 10317 | // When SSL proxy is not in use, socket must be requested from |
| 10318 | // |transport_conn_pool|. |
| 10319 | EXPECT_EQ(!tests[i].ssl, transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10320 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10321 | } |
| 10322 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10323 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10324 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10325 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10326 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 10327 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10328 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10329 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10330 | // SSL Tests |
| 10331 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10332 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 10333 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10334 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10335 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10336 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10337 | "http_proxy", "https://host.with.alternate/direct", |
| 10338 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10339 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 10340 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10341 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10342 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 10343 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10344 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10345 | }; |
| 10346 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10347 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10348 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10349 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10350 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10351 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10352 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10353 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10354 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10355 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10356 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10357 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10358 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10359 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10360 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10361 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10362 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 10363 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 10364 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10365 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10366 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10367 | |
| 10368 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10369 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10370 | if (tests[i].ssl) |
| 10371 | EXPECT_EQ(tests[i].expected_group_name, |
| 10372 | ssl_conn_pool->last_group_name_received()); |
| 10373 | else |
| 10374 | EXPECT_EQ(tests[i].expected_group_name, |
| 10375 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10376 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10377 | } |
| 10378 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10379 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10380 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10381 | { |
| 10382 | "socks4://socks_proxy:1080", |
| 10383 | "http://www.example.org/socks4_direct", |
| 10384 | "socks4/www.example.org:80", |
| 10385 | false, |
| 10386 | }, |
| 10387 | { |
| 10388 | "socks5://socks_proxy:1080", |
| 10389 | "http://www.example.org/socks5_direct", |
| 10390 | "socks5/www.example.org:80", |
| 10391 | false, |
| 10392 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10393 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10394 | // SSL Tests |
| 10395 | { |
| 10396 | "socks4://socks_proxy:1080", |
| 10397 | "https://www.example.org/socks4_ssl", |
| 10398 | "socks4/ssl/www.example.org:443", |
| 10399 | true, |
| 10400 | }, |
| 10401 | { |
| 10402 | "socks5://socks_proxy:1080", |
| 10403 | "https://www.example.org/socks5_ssl", |
| 10404 | "socks5/ssl/www.example.org:443", |
| 10405 | true, |
| 10406 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10407 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10408 | { |
| 10409 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10410 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10411 | "socks4/ssl/host.with.alternate:443", |
| 10412 | true, |
| 10413 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10414 | }; |
| 10415 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10416 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10417 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10418 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10419 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10420 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10421 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 10422 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10423 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10424 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10425 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10426 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10427 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10428 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10429 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10430 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10431 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 10432 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 10433 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10434 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10435 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10436 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10437 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10438 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10439 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10440 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10441 | if (tests[i].ssl) |
| 10442 | EXPECT_EQ(tests[i].expected_group_name, |
| 10443 | ssl_conn_pool->last_group_name_received()); |
| 10444 | else |
| 10445 | EXPECT_EQ(tests[i].expected_group_name, |
| 10446 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10447 | } |
| 10448 | } |
| 10449 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10450 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10451 | HttpRequestInfo request; |
| 10452 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10453 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10454 | request.traffic_annotation = |
| 10455 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10456 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10457 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10458 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10459 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 10460 | // This simulates failure resolving all hostnames; that means we will fail |
| 10461 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10462 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10463 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10464 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10465 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10466 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10467 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10468 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10469 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10471 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10472 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10473 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10474 | } |
| 10475 | |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 10476 | // LOAD_BYPASS_CACHE should trigger the host cache bypass. |
| 10477 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10478 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10479 | HttpRequestInfo request_info; |
| 10480 | request_info.method = "GET"; |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 10481 | request_info.load_flags = LOAD_BYPASS_CACHE; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10482 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10483 | request_info.traffic_annotation = |
| 10484 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10485 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 10486 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10487 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10488 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10489 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10490 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10491 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10492 | // 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] | 10493 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10494 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10495 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10496 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10497 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10498 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10499 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10500 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10501 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10502 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10503 | |
| 10504 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 10505 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10506 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10507 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10508 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10509 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10510 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10511 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10512 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10513 | // 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] | 10514 | // we can tell if the next lookup hit the cache, or the "network". |
| 10515 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10516 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10517 | |
| 10518 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 10519 | // 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] | 10520 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10521 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10522 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10523 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10524 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10525 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10526 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10527 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10528 | |
| 10529 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10530 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10531 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10532 | } |
| 10533 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10534 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10535 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10536 | HttpRequestInfo request; |
| 10537 | request.method = "GET"; |
| 10538 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10539 | request.traffic_annotation = |
| 10540 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10541 | |
| 10542 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10543 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10544 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10545 | StaticSocketDataProvider data(NULL, 0, |
| 10546 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10547 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10548 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10549 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10550 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10551 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10552 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10553 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10554 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10556 | |
| 10557 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10558 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10559 | |
| 10560 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10561 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10562 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10563 | } |
| 10564 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10565 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10566 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10567 | HttpRequestInfo request; |
| 10568 | request.method = "GET"; |
| 10569 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10570 | request.traffic_annotation = |
| 10571 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10572 | |
| 10573 | MockRead data_reads[] = { |
| 10574 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10575 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10576 | }; |
| 10577 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10578 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10579 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10580 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10582 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10583 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10584 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10585 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10586 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10587 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10588 | |
| 10589 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10590 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10591 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10592 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10593 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10594 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10595 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10596 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10597 | |
| 10598 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10599 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10600 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10601 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10602 | |
| 10603 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10604 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10605 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10606 | } |
| 10607 | |
| 10608 | // Make sure that a dropped connection while draining the body for auth |
| 10609 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10610 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10611 | HttpRequestInfo request; |
| 10612 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10613 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10614 | request.traffic_annotation = |
| 10615 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10616 | |
| 10617 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10618 | MockWrite( |
| 10619 | "GET / HTTP/1.1\r\n" |
| 10620 | "Host: www.example.org\r\n" |
| 10621 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10622 | }; |
| 10623 | |
| 10624 | MockRead data_reads1[] = { |
| 10625 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 10626 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10627 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10628 | MockRead("Content-Length: 14\r\n\r\n"), |
| 10629 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10630 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10631 | }; |
| 10632 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10633 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10634 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10635 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10636 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10637 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10638 | // be issuing -- the final header line contains the credentials. |
| 10639 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10640 | MockWrite( |
| 10641 | "GET / HTTP/1.1\r\n" |
| 10642 | "Host: www.example.org\r\n" |
| 10643 | "Connection: keep-alive\r\n" |
| 10644 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10645 | }; |
| 10646 | |
| 10647 | // Lastly, the server responds with the actual content. |
| 10648 | MockRead data_reads2[] = { |
| 10649 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10650 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10651 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10652 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10653 | }; |
| 10654 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10655 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10656 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10657 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10659 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10660 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10661 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10662 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10663 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10664 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10666 | |
| 10667 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10668 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10669 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10670 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10671 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10672 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10673 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10674 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10675 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10676 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10677 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10678 | |
| 10679 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10680 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10681 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10682 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10683 | ASSERT_TRUE(response); |
| 10684 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10685 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10686 | } |
| 10687 | |
| 10688 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10689 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10690 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10691 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10692 | |
| 10693 | HttpRequestInfo request; |
| 10694 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10695 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10696 | request.traffic_annotation = |
| 10697 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10698 | |
| 10699 | MockRead proxy_reads[] = { |
| 10700 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10701 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10702 | }; |
| 10703 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10704 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10705 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10706 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10707 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10708 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10709 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10710 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10711 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10712 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10713 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10714 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10715 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10716 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10717 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10719 | |
| 10720 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10721 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10722 | } |
| 10723 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10724 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10725 | HttpRequestInfo request; |
| 10726 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10727 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10728 | request.traffic_annotation = |
| 10729 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10730 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10732 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10733 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10734 | MockRead data_reads[] = { |
| 10735 | 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] | 10736 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10737 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10738 | |
| 10739 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10740 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10741 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10742 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10743 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10744 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10745 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10746 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10747 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10748 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10749 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10750 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10751 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10752 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10753 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10754 | |
| 10755 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10756 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10757 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10758 | } |
| 10759 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10760 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10761 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10762 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10763 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10764 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10765 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10766 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10767 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10768 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10769 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10770 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10771 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10772 | |
| 10773 | HttpRequestInfo request; |
| 10774 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10775 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10776 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10777 | request.traffic_annotation = |
| 10778 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10779 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10781 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10782 | |
| 10783 | MockRead data_reads[] = { |
| 10784 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10785 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10786 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10787 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10788 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10789 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10790 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10791 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10792 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10793 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10794 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10795 | |
| 10796 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10797 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10798 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10799 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10800 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10801 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10802 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10803 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10804 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10805 | } |
| 10806 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10807 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10808 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10809 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10810 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10811 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10812 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10813 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10814 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10815 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10816 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10817 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10818 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10819 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10820 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10821 | |
| 10822 | HttpRequestInfo request; |
| 10823 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10824 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10825 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10826 | request.traffic_annotation = |
| 10827 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10828 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10829 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10830 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10831 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10832 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10833 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10834 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10836 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10837 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10838 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10839 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10840 | |
| 10841 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10842 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10843 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10844 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10845 | } |
| 10846 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10847 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10848 | class FakeUploadElementReader : public UploadElementReader { |
| 10849 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 10850 | FakeUploadElementReader() = default; |
| 10851 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10852 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10853 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10854 | |
| 10855 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10856 | int Init(CompletionOnceCallback callback) override { |
| 10857 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10858 | return ERR_IO_PENDING; |
| 10859 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10860 | uint64_t GetContentLength() const override { return 0; } |
| 10861 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10862 | int Read(IOBuffer* buf, |
| 10863 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10864 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10865 | return ERR_FAILED; |
| 10866 | } |
| 10867 | |
| 10868 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10869 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10870 | }; |
| 10871 | |
| 10872 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10873 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10874 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10875 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10876 | |
| 10877 | HttpRequestInfo request; |
| 10878 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10879 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10880 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10881 | request.traffic_annotation = |
| 10882 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10883 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10884 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10885 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10886 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10887 | |
| 10888 | StaticSocketDataProvider data; |
| 10889 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10890 | |
| 10891 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10892 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10894 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10895 | |
| 10896 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10897 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 10898 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10899 | |
| 10900 | // Return Init()'s result after the transaction gets destroyed. |
| 10901 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10902 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10903 | } |
| 10904 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10905 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10906 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10907 | HttpRequestInfo request; |
| 10908 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10909 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10910 | request.traffic_annotation = |
| 10911 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10912 | |
| 10913 | // First transaction will request a resource and receive a Basic challenge |
| 10914 | // with realm="first_realm". |
| 10915 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10916 | MockWrite( |
| 10917 | "GET / HTTP/1.1\r\n" |
| 10918 | "Host: www.example.org\r\n" |
| 10919 | "Connection: keep-alive\r\n" |
| 10920 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10921 | }; |
| 10922 | MockRead data_reads1[] = { |
| 10923 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10924 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10925 | "\r\n"), |
| 10926 | }; |
| 10927 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10928 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10929 | // for first_realm. The server will reject and provide a challenge with |
| 10930 | // second_realm. |
| 10931 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10932 | MockWrite( |
| 10933 | "GET / HTTP/1.1\r\n" |
| 10934 | "Host: www.example.org\r\n" |
| 10935 | "Connection: keep-alive\r\n" |
| 10936 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10937 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10938 | }; |
| 10939 | MockRead data_reads2[] = { |
| 10940 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10941 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10942 | "\r\n"), |
| 10943 | }; |
| 10944 | |
| 10945 | // This again fails, and goes back to first_realm. Make sure that the |
| 10946 | // entry is removed from cache. |
| 10947 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10948 | MockWrite( |
| 10949 | "GET / HTTP/1.1\r\n" |
| 10950 | "Host: www.example.org\r\n" |
| 10951 | "Connection: keep-alive\r\n" |
| 10952 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10953 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10954 | }; |
| 10955 | MockRead data_reads3[] = { |
| 10956 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10957 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10958 | "\r\n"), |
| 10959 | }; |
| 10960 | |
| 10961 | // Try one last time (with the correct password) and get the resource. |
| 10962 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10963 | MockWrite( |
| 10964 | "GET / HTTP/1.1\r\n" |
| 10965 | "Host: www.example.org\r\n" |
| 10966 | "Connection: keep-alive\r\n" |
| 10967 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10968 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10969 | }; |
| 10970 | MockRead data_reads4[] = { |
| 10971 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10972 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10973 | "Content-Length: 5\r\n" |
| 10974 | "\r\n" |
| 10975 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10976 | }; |
| 10977 | |
| 10978 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10979 | data_writes1, arraysize(data_writes1)); |
| 10980 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10981 | data_writes2, arraysize(data_writes2)); |
| 10982 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 10983 | data_writes3, arraysize(data_writes3)); |
| 10984 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 10985 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10986 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10987 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10988 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10989 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10991 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10992 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10993 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10994 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10995 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10996 | // Issue the first request with Authorize headers. There should be a |
| 10997 | // password prompt for first_realm waiting to be filled in after the |
| 10998 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10999 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11000 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11001 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11002 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11003 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11004 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11005 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11006 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11007 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11008 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11009 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11010 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11011 | |
| 11012 | // Issue the second request with an incorrect password. There should be a |
| 11013 | // password prompt for second_realm waiting to be filled in after the |
| 11014 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11015 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11016 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11017 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11018 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11019 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11020 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11021 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11022 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11023 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11024 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11025 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11026 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11027 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11028 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11029 | |
| 11030 | // Issue the third request with another incorrect password. There should be |
| 11031 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11032 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11033 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11034 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11035 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11036 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11037 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11038 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11039 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11040 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11041 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11042 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11043 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11044 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11045 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11046 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11047 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11048 | |
| 11049 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11050 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11051 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11052 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11053 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11054 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11055 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11056 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11057 | ASSERT_TRUE(response); |
| 11058 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11059 | } |
| 11060 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11061 | // Regression test for https://crbug.com/754395. |
| 11062 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 11063 | MockRead data_reads[] = { |
| 11064 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11065 | MockRead(kAlternativeServiceHttpHeader), |
| 11066 | MockRead("\r\n"), |
| 11067 | MockRead("hello world"), |
| 11068 | MockRead(SYNCHRONOUS, OK), |
| 11069 | }; |
| 11070 | |
| 11071 | HttpRequestInfo request; |
| 11072 | request.method = "GET"; |
| 11073 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11074 | request.traffic_annotation = |
| 11075 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11076 | |
| 11077 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11078 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11079 | |
| 11080 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11081 | ssl.ssl_info.cert = |
| 11082 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11083 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11084 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11085 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11086 | |
| 11087 | TestCompletionCallback callback; |
| 11088 | |
| 11089 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11090 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11091 | |
| 11092 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11094 | |
| 11095 | url::SchemeHostPort test_server(request.url); |
| 11096 | HttpServerProperties* http_server_properties = |
| 11097 | session->http_server_properties(); |
| 11098 | EXPECT_TRUE( |
| 11099 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11100 | |
| 11101 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11102 | |
| 11103 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11104 | ASSERT_TRUE(response); |
| 11105 | ASSERT_TRUE(response->headers); |
| 11106 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11107 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11108 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11109 | |
| 11110 | std::string response_data; |
| 11111 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11112 | EXPECT_EQ("hello world", response_data); |
| 11113 | |
| 11114 | EXPECT_TRUE( |
| 11115 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11116 | } |
| 11117 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11118 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11119 | MockRead data_reads[] = { |
| 11120 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11121 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11122 | MockRead("\r\n"), |
| 11123 | MockRead("hello world"), |
| 11124 | MockRead(SYNCHRONOUS, OK), |
| 11125 | }; |
| 11126 | |
| 11127 | HttpRequestInfo request; |
| 11128 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11129 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11130 | request.traffic_annotation = |
| 11131 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11132 | |
| 11133 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11134 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11135 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11136 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11137 | ssl.ssl_info.cert = |
| 11138 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11139 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11140 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11141 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11142 | TestCompletionCallback callback; |
| 11143 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11144 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11145 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11146 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11147 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11148 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11149 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11150 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11151 | HttpServerProperties* http_server_properties = |
| 11152 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11153 | EXPECT_TRUE( |
| 11154 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11155 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11156 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11158 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11159 | ASSERT_TRUE(response); |
| 11160 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11161 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11162 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11163 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11164 | |
| 11165 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11166 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11167 | EXPECT_EQ("hello world", response_data); |
| 11168 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11169 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11170 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11171 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11172 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 11173 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11174 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11175 | } |
| 11176 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11177 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11178 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11179 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11180 | MockRead data_reads[] = { |
| 11181 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11182 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11183 | MockRead("\r\n"), |
| 11184 | MockRead("hello world"), |
| 11185 | MockRead(SYNCHRONOUS, OK), |
| 11186 | }; |
| 11187 | |
| 11188 | HttpRequestInfo request; |
| 11189 | request.method = "GET"; |
| 11190 | request.url = GURL("http://www.example.org/"); |
| 11191 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11192 | request.traffic_annotation = |
| 11193 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11194 | |
| 11195 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11196 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11197 | |
| 11198 | TestCompletionCallback callback; |
| 11199 | |
| 11200 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11201 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11202 | |
| 11203 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11204 | HttpServerProperties* http_server_properties = |
| 11205 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11206 | EXPECT_TRUE( |
| 11207 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11208 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11209 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11210 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11211 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11212 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11213 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11214 | ASSERT_TRUE(response); |
| 11215 | ASSERT_TRUE(response->headers); |
| 11216 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11217 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11218 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11219 | |
| 11220 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11221 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11222 | EXPECT_EQ("hello world", response_data); |
| 11223 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11224 | EXPECT_TRUE( |
| 11225 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11226 | } |
| 11227 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11228 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11229 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11230 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11231 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11232 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11233 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11234 | HttpRequestInfo request; |
| 11235 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11236 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11237 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11238 | request.traffic_annotation = |
| 11239 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11240 | |
| 11241 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11242 | StaticSocketDataProvider first_data; |
| 11243 | first_data.set_connect_data(mock_connect); |
| 11244 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11245 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11246 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11247 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11248 | |
| 11249 | MockRead data_reads[] = { |
| 11250 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11251 | MockRead(ASYNC, OK), |
| 11252 | }; |
| 11253 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 11254 | 0); |
| 11255 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11256 | |
| 11257 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11258 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11259 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11260 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11261 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 11262 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11263 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11264 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11265 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11266 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11267 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11268 | TestCompletionCallback callback; |
| 11269 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11270 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11271 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11272 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11273 | } |
| 11274 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11275 | // Regression test for https://crbug.com/615497: |
| 11276 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11277 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11278 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11279 | HttpRequestInfo request; |
| 11280 | request.method = "GET"; |
| 11281 | request.url = GURL("http://www.example.org/"); |
| 11282 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11283 | request.traffic_annotation = |
| 11284 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11285 | |
| 11286 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11287 | StaticSocketDataProvider first_data; |
| 11288 | first_data.set_connect_data(mock_connect); |
| 11289 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 11290 | |
| 11291 | MockRead data_reads[] = { |
| 11292 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11293 | MockRead(ASYNC, OK), |
| 11294 | }; |
| 11295 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 11296 | 0); |
| 11297 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11298 | |
| 11299 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11300 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11301 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11302 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11303 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11304 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11305 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11306 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11307 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11308 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11309 | TestCompletionCallback callback; |
| 11310 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11311 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11312 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11313 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11314 | } |
| 11315 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11316 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11317 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11318 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11319 | HttpServerProperties* http_server_properties = |
| 11320 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11321 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11322 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11323 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11324 | http_server_properties->SetQuicAlternativeService( |
| 11325 | test_server, alternative_service, expiration, |
| 11326 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11327 | EXPECT_EQ( |
| 11328 | 1u, |
| 11329 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11330 | |
| 11331 | // Send a clear header. |
| 11332 | MockRead data_reads[] = { |
| 11333 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11334 | MockRead("Alt-Svc: clear\r\n"), |
| 11335 | MockRead("\r\n"), |
| 11336 | MockRead("hello world"), |
| 11337 | MockRead(SYNCHRONOUS, OK), |
| 11338 | }; |
| 11339 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 11340 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11341 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11342 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11343 | ssl.ssl_info.cert = |
| 11344 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11345 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11346 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11347 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11348 | HttpRequestInfo request; |
| 11349 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11350 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11351 | request.traffic_annotation = |
| 11352 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11353 | |
| 11354 | TestCompletionCallback callback; |
| 11355 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11356 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11357 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11358 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11359 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11360 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11361 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11362 | ASSERT_TRUE(response); |
| 11363 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11364 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11365 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11366 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11367 | |
| 11368 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11369 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11370 | EXPECT_EQ("hello world", response_data); |
| 11371 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11372 | EXPECT_TRUE( |
| 11373 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11374 | } |
| 11375 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11376 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11377 | MockRead data_reads[] = { |
| 11378 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11379 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 11380 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11381 | MockRead("hello world"), |
| 11382 | MockRead(SYNCHRONOUS, OK), |
| 11383 | }; |
| 11384 | |
| 11385 | HttpRequestInfo request; |
| 11386 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11387 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11388 | request.traffic_annotation = |
| 11389 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11390 | |
| 11391 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11392 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11393 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11394 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11395 | ssl.ssl_info.cert = |
| 11396 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11397 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11398 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11399 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11400 | TestCompletionCallback callback; |
| 11401 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11402 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11403 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11404 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11405 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11406 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11407 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11408 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11409 | HttpServerProperties* http_server_properties = |
| 11410 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11411 | EXPECT_TRUE( |
| 11412 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11413 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11414 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11415 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11416 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11417 | ASSERT_TRUE(response); |
| 11418 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11419 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11420 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11421 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11422 | |
| 11423 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11424 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11425 | EXPECT_EQ("hello world", response_data); |
| 11426 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11427 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11428 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11429 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 11430 | |
| 11431 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 11432 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11433 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11434 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 11435 | 1234); |
| 11436 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11437 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11438 | } |
| 11439 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11440 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11441 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11442 | HostPortPair alternative("alternative.example.org", 443); |
| 11443 | std::string origin_url = "https://origin.example.org:443"; |
| 11444 | std::string alternative_url = "https://alternative.example.org:443"; |
| 11445 | |
| 11446 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 11447 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11448 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11449 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11450 | |
| 11451 | // HTTP/1.1 data for request. |
| 11452 | MockWrite http_writes[] = { |
| 11453 | MockWrite("GET / HTTP/1.1\r\n" |
| 11454 | "Host: alternative.example.org\r\n" |
| 11455 | "Connection: keep-alive\r\n\r\n"), |
| 11456 | }; |
| 11457 | |
| 11458 | MockRead http_reads[] = { |
| 11459 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11460 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11461 | "Content-Length: 40\r\n\r\n" |
| 11462 | "first HTTP/1.1 response from alternative"), |
| 11463 | }; |
| 11464 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11465 | http_writes, arraysize(http_writes)); |
| 11466 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11467 | |
| 11468 | StaticSocketDataProvider data_refused; |
| 11469 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11470 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11471 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11472 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11473 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11474 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11475 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11476 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11477 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11478 | http_server_properties->SetQuicAlternativeService( |
| 11479 | server, alternative_service, expiration, |
| 11480 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11481 | // Mark the QUIC alternative service as broken. |
| 11482 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 11483 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11484 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11485 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11486 | request.method = "GET"; |
| 11487 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11488 | request.traffic_annotation = |
| 11489 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11490 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11491 | TestCompletionCallback callback; |
| 11492 | NetErrorDetails details; |
| 11493 | EXPECT_FALSE(details.quic_broken); |
| 11494 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11495 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11496 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11497 | EXPECT_TRUE(details.quic_broken); |
| 11498 | } |
| 11499 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11500 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11501 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11502 | HostPortPair alternative1("alternative1.example.org", 443); |
| 11503 | HostPortPair alternative2("alternative2.example.org", 443); |
| 11504 | std::string origin_url = "https://origin.example.org:443"; |
| 11505 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 11506 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 11507 | |
| 11508 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 11509 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11510 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11511 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11512 | |
| 11513 | // HTTP/1.1 data for request. |
| 11514 | MockWrite http_writes[] = { |
| 11515 | MockWrite("GET / HTTP/1.1\r\n" |
| 11516 | "Host: alternative1.example.org\r\n" |
| 11517 | "Connection: keep-alive\r\n\r\n"), |
| 11518 | }; |
| 11519 | |
| 11520 | MockRead http_reads[] = { |
| 11521 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11522 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11523 | "Content-Length: 40\r\n\r\n" |
| 11524 | "first HTTP/1.1 response from alternative1"), |
| 11525 | }; |
| 11526 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11527 | http_writes, arraysize(http_writes)); |
| 11528 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11529 | |
| 11530 | StaticSocketDataProvider data_refused; |
| 11531 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11532 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11533 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11534 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11535 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11536 | session->http_server_properties(); |
| 11537 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11538 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11539 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 11540 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11541 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11542 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11543 | alternative_service_info_vector.push_back( |
| 11544 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11545 | alternative_service1, expiration, |
| 11546 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11547 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11548 | alternative_service_info_vector.push_back( |
| 11549 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11550 | alternative_service2, expiration, |
| 11551 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11552 | |
| 11553 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11554 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11555 | |
| 11556 | // Mark one of the QUIC alternative service as broken. |
| 11557 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11558 | EXPECT_EQ(2u, |
| 11559 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11560 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11561 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11562 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11563 | request.method = "GET"; |
| 11564 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11565 | request.traffic_annotation = |
| 11566 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11567 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11568 | TestCompletionCallback callback; |
| 11569 | NetErrorDetails details; |
| 11570 | EXPECT_FALSE(details.quic_broken); |
| 11571 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11572 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11573 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11574 | EXPECT_FALSE(details.quic_broken); |
| 11575 | } |
| 11576 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11577 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11578 | HttpRequestInfo request; |
| 11579 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11580 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11581 | request.traffic_annotation = |
| 11582 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11583 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11584 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11585 | StaticSocketDataProvider first_data; |
| 11586 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11587 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11588 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11589 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11590 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11591 | |
| 11592 | MockRead data_reads[] = { |
| 11593 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11594 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11595 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11596 | }; |
| 11597 | StaticSocketDataProvider second_data( |
| 11598 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11599 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11600 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11601 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11602 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11603 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11604 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11605 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11606 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 11607 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11608 | // Port is ignored by MockConnect anyway. |
| 11609 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11610 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11611 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11612 | http_server_properties->SetHttp2AlternativeService( |
| 11613 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11614 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11615 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11616 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11617 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11618 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11619 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11620 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11621 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11622 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11623 | ASSERT_TRUE(response); |
| 11624 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11625 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11626 | |
| 11627 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11628 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11629 | EXPECT_EQ("hello world", response_data); |
| 11630 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11631 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 11632 | http_server_properties->GetAlternativeServiceInfos(server); |
| 11633 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11634 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11635 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11636 | EXPECT_TRUE( |
| 11637 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11638 | } |
| 11639 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11640 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11641 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11642 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11643 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11644 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11645 | HttpRequestInfo restricted_port_request; |
| 11646 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11647 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11648 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11649 | restricted_port_request.traffic_annotation = |
| 11650 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11651 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11652 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11653 | StaticSocketDataProvider first_data; |
| 11654 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11655 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11656 | |
| 11657 | MockRead data_reads[] = { |
| 11658 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11659 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11660 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11661 | }; |
| 11662 | StaticSocketDataProvider second_data( |
| 11663 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11664 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11665 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11666 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11667 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11668 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11669 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11670 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11671 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11672 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11673 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11674 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11675 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11676 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11677 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11678 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11679 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11680 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11681 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11682 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11683 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11684 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11685 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11686 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11687 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11688 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11689 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11690 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11691 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 11692 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 11693 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11694 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11695 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11696 | |
| 11697 | HttpRequestInfo restricted_port_request; |
| 11698 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11699 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11700 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11701 | restricted_port_request.traffic_annotation = |
| 11702 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11703 | |
| 11704 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11705 | StaticSocketDataProvider first_data; |
| 11706 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11707 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11708 | |
| 11709 | MockRead data_reads[] = { |
| 11710 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11711 | MockRead("hello world"), |
| 11712 | MockRead(ASYNC, OK), |
| 11713 | }; |
| 11714 | StaticSocketDataProvider second_data( |
| 11715 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11716 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11717 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11718 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11719 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11720 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11721 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11722 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11723 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11724 | session->http_server_properties(); |
| 11725 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11726 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11727 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11728 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11729 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11730 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11731 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11732 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11733 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11734 | TestCompletionCallback callback; |
| 11735 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11736 | EXPECT_EQ(ERR_IO_PENDING, |
| 11737 | trans.Start(&restricted_port_request, callback.callback(), |
| 11738 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11739 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11740 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11741 | } |
| 11742 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11743 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11744 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11745 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11746 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11747 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11748 | HttpRequestInfo restricted_port_request; |
| 11749 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11750 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11751 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11752 | restricted_port_request.traffic_annotation = |
| 11753 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11754 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11755 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11756 | StaticSocketDataProvider first_data; |
| 11757 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11758 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11759 | |
| 11760 | MockRead data_reads[] = { |
| 11761 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11762 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11763 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11764 | }; |
| 11765 | StaticSocketDataProvider second_data( |
| 11766 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11767 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11768 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11769 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11770 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11771 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11772 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11773 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11774 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11775 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11776 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11777 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11778 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11779 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11780 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11781 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11782 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11783 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11784 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11785 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11786 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11787 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11788 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11789 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11790 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11791 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11792 | } |
| 11793 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11794 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11795 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11796 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11797 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11798 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11799 | HttpRequestInfo unrestricted_port_request; |
| 11800 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11801 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11802 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11803 | unrestricted_port_request.traffic_annotation = |
| 11804 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11805 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11806 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11807 | StaticSocketDataProvider first_data; |
| 11808 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11809 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11810 | |
| 11811 | MockRead data_reads[] = { |
| 11812 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11813 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11814 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11815 | }; |
| 11816 | StaticSocketDataProvider second_data( |
| 11817 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11818 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11819 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11820 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11821 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11822 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11823 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11824 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11825 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11826 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11827 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11828 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11829 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11830 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11831 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11832 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11833 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11835 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11836 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11837 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11838 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11839 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11841 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11842 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11843 | } |
| 11844 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11845 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11846 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11847 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11848 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11849 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11850 | HttpRequestInfo unrestricted_port_request; |
| 11851 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11852 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11853 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11854 | unrestricted_port_request.traffic_annotation = |
| 11855 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11856 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11857 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11858 | StaticSocketDataProvider first_data; |
| 11859 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11860 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11861 | |
| 11862 | MockRead data_reads[] = { |
| 11863 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11864 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11865 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11866 | }; |
| 11867 | StaticSocketDataProvider second_data( |
| 11868 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11869 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11870 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11871 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11872 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11873 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11874 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11875 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11876 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11877 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11878 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11879 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11880 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11881 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11882 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11883 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11884 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11885 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11886 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11887 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11889 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11890 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11891 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11892 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11893 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11894 | } |
| 11895 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11896 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11897 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 11898 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11899 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11900 | HttpRequestInfo request; |
| 11901 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11902 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11903 | request.traffic_annotation = |
| 11904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11905 | |
| 11906 | // The alternate protocol request will error out before we attempt to connect, |
| 11907 | // so only the standard HTTP request will try to connect. |
| 11908 | MockRead data_reads[] = { |
| 11909 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11910 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11911 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11912 | }; |
| 11913 | StaticSocketDataProvider data( |
| 11914 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11915 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11916 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11917 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11918 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11919 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11920 | session->http_server_properties(); |
| 11921 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11922 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11923 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11924 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11925 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11926 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11927 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11928 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11929 | TestCompletionCallback callback; |
| 11930 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11931 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11932 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11933 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11934 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11935 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11936 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11937 | ASSERT_TRUE(response); |
| 11938 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11939 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11940 | |
| 11941 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11942 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11943 | EXPECT_EQ("hello world", response_data); |
| 11944 | } |
| 11945 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11946 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11947 | HttpRequestInfo request; |
| 11948 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11949 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11950 | request.traffic_annotation = |
| 11951 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11952 | |
| 11953 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11954 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11955 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11956 | MockRead("\r\n"), |
| 11957 | MockRead("hello world"), |
| 11958 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11959 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11960 | |
| 11961 | StaticSocketDataProvider first_transaction( |
| 11962 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11963 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11964 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11965 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11966 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11967 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11968 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11969 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11970 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11971 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11972 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11973 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11974 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11975 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11976 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11977 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11978 | }; |
| 11979 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11980 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11981 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11982 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11983 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11984 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11985 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11986 | NULL, 0, NULL, 0); |
| 11987 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11988 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11989 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11990 | &hanging_non_alternate_protocol_socket); |
| 11991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11992 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11993 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11994 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11995 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11996 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11997 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11998 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11999 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12000 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12001 | |
| 12002 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12003 | ASSERT_TRUE(response); |
| 12004 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12005 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12006 | |
| 12007 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12008 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12009 | EXPECT_EQ("hello world", response_data); |
| 12010 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12011 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12012 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12013 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12014 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12015 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12016 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12017 | |
| 12018 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12019 | ASSERT_TRUE(response); |
| 12020 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12021 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12022 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12023 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12024 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12025 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12026 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12027 | } |
| 12028 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12029 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12030 | HttpRequestInfo request; |
| 12031 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12032 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12033 | request.traffic_annotation = |
| 12034 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12035 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12036 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12037 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12038 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12039 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12040 | MockRead("\r\n"), |
| 12041 | MockRead("hello world"), |
| 12042 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12043 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12044 | }; |
| 12045 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12046 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 12047 | 0); |
| 12048 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12049 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12050 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12051 | ssl_http11.ssl_info.cert = |
| 12052 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12053 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12054 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12055 | |
| 12056 | // Second transaction starts an alternative and a non-alternative Job. |
| 12057 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12058 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12059 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 12060 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12061 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12062 | |
| 12063 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 12064 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12065 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12066 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12067 | // Third transaction starts an alternative and a non-alternative job. |
| 12068 | // The non-alternative job hangs, but the alternative one succeeds. |
| 12069 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12070 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12071 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12072 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12073 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12074 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12075 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12076 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12077 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12078 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12079 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12080 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12081 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12082 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12083 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12084 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12085 | }; |
| 12086 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12087 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12088 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12089 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12090 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12091 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12092 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12093 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 12094 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12095 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12096 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12097 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12098 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12099 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12100 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12101 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12102 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12103 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12104 | |
| 12105 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12106 | ASSERT_TRUE(response); |
| 12107 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12108 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12109 | |
| 12110 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12111 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12112 | EXPECT_EQ("hello world", response_data); |
| 12113 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12114 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12115 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12116 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12117 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12118 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12119 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12120 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12121 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12122 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12123 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12124 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12125 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12126 | |
| 12127 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12128 | ASSERT_TRUE(response); |
| 12129 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12130 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12131 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12132 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12133 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12134 | EXPECT_EQ("hello!", response_data); |
| 12135 | |
| 12136 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12137 | ASSERT_TRUE(response); |
| 12138 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12139 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12140 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12141 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12142 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12143 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12144 | } |
| 12145 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12146 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12147 | HttpRequestInfo request; |
| 12148 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12149 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12150 | request.traffic_annotation = |
| 12151 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12152 | |
| 12153 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12154 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12155 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12156 | MockRead("\r\n"), |
| 12157 | MockRead("hello world"), |
| 12158 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12159 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12160 | }; |
| 12161 | |
| 12162 | StaticSocketDataProvider first_transaction( |
| 12163 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12164 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12165 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12166 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12167 | ssl.ssl_info.cert = |
| 12168 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12169 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12170 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12171 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12172 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12173 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 12174 | NULL, 0, NULL, 0); |
| 12175 | hanging_alternate_protocol_socket.set_connect_data( |
| 12176 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12177 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12178 | &hanging_alternate_protocol_socket); |
| 12179 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12180 | // 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] | 12181 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 12182 | NULL, 0); |
| 12183 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12184 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12185 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12186 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12187 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12188 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12189 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12190 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12191 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12192 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12193 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12194 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12195 | |
| 12196 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12197 | ASSERT_TRUE(response); |
| 12198 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12199 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12200 | |
| 12201 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12202 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12203 | EXPECT_EQ("hello world", response_data); |
| 12204 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12205 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12206 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12207 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12208 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12209 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12210 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12211 | |
| 12212 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12213 | ASSERT_TRUE(response); |
| 12214 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12215 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12216 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12217 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12218 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12219 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12220 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12221 | } |
| 12222 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12223 | class CapturingProxyResolver : public ProxyResolver { |
| 12224 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 12225 | CapturingProxyResolver() = default; |
| 12226 | ~CapturingProxyResolver() override = default; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12227 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12228 | int GetProxyForURL(const GURL& url, |
| 12229 | ProxyInfo* results, |
| 12230 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 12231 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12232 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 12233 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 12234 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12235 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12236 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12237 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12238 | } |
| 12239 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 12240 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 12241 | |
| 12242 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12243 | std::vector<GURL> resolved_; |
| 12244 | |
| 12245 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 12246 | }; |
| 12247 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12248 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 12249 | public: |
| 12250 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 12251 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 12252 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 12253 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 12254 | std::unique_ptr<ProxyResolver>* resolver, |
| 12255 | const net::CompletionCallback& callback, |
| 12256 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12257 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12258 | return OK; |
| 12259 | } |
| 12260 | |
| 12261 | private: |
| 12262 | ProxyResolver* resolver_; |
| 12263 | }; |
| 12264 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12265 | // Test that proxy is resolved using the origin url, |
| 12266 | // regardless of the alternative server. |
| 12267 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 12268 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 12269 | ProxyConfig proxy_config; |
| 12270 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 12271 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12272 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 12273 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12274 | |
| 12275 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12276 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12277 | &capturing_proxy_resolver); |
| 12278 | |
| 12279 | TestNetLog net_log; |
| 12280 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 12281 | session_deps_.proxy_resolution_service = |
| 12282 | std::make_unique<ProxyResolutionService>( |
| 12283 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 12284 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12285 | |
| 12286 | session_deps_.net_log = &net_log; |
| 12287 | |
| 12288 | // Configure alternative service with a hostname that is not bypassed by the |
| 12289 | // proxy. |
| 12290 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12291 | HttpServerProperties* http_server_properties = |
| 12292 | session->http_server_properties(); |
| 12293 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 12294 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12295 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12296 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12297 | http_server_properties->SetHttp2AlternativeService( |
| 12298 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12299 | |
| 12300 | // Non-alternative job should hang. |
| 12301 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 12302 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 12303 | nullptr, 0); |
| 12304 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 12305 | session_deps_.socket_factory->AddSocketDataProvider( |
| 12306 | &hanging_alternate_protocol_socket); |
| 12307 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12308 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12309 | |
| 12310 | HttpRequestInfo request; |
| 12311 | request.method = "GET"; |
| 12312 | request.url = GURL("https://www.example.org/"); |
| 12313 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12314 | request.traffic_annotation = |
| 12315 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12316 | |
| 12317 | SpdySerializedFrame req( |
| 12318 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 12319 | |
| 12320 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 12321 | |
| 12322 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 12323 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 12324 | MockRead spdy_reads[] = { |
| 12325 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 12326 | }; |
| 12327 | |
| 12328 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12329 | arraysize(spdy_writes)); |
| 12330 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 12331 | |
| 12332 | TestCompletionCallback callback; |
| 12333 | |
| 12334 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12335 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12336 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12337 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 12338 | |
| 12339 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12340 | ASSERT_TRUE(response); |
| 12341 | ASSERT_TRUE(response->headers); |
| 12342 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 12343 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12344 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12345 | |
| 12346 | std::string response_data; |
| 12347 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12348 | EXPECT_EQ("hello!", response_data); |
| 12349 | |
| 12350 | // Origin host bypasses proxy, no resolution should have happened. |
| 12351 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 12352 | } |
| 12353 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12354 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12355 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12356 | proxy_config.set_auto_detect(true); |
| 12357 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 12358 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12359 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12360 | session_deps_.proxy_resolution_service = |
| 12361 | std::make_unique<ProxyResolutionService>( |
| 12362 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 12363 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 12364 | std::make_unique<CapturingProxyResolverFactory>( |
| 12365 | &capturing_proxy_resolver), |
| 12366 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12367 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12368 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12369 | |
| 12370 | HttpRequestInfo request; |
| 12371 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12372 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12373 | request.traffic_annotation = |
| 12374 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12375 | |
| 12376 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12377 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12378 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12379 | MockRead("\r\n"), |
| 12380 | MockRead("hello world"), |
| 12381 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12382 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12383 | }; |
| 12384 | |
| 12385 | StaticSocketDataProvider first_transaction( |
| 12386 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12387 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12388 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12389 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12390 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12391 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12392 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12393 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12394 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12395 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12396 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12397 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12398 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12399 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12400 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12401 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12402 | }; |
| 12403 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12404 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 12405 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12406 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12407 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12408 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12409 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 12410 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12411 | }; |
| 12412 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12413 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12414 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12415 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12416 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12417 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12418 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 12419 | NULL, 0, NULL, 0); |
| 12420 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12421 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12422 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12423 | &hanging_non_alternate_protocol_socket); |
| 12424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12425 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12426 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12427 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12428 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12429 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12430 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12431 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12432 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12433 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12434 | |
| 12435 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12436 | ASSERT_TRUE(response); |
| 12437 | ASSERT_TRUE(response->headers); |
| 12438 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 12439 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12440 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12441 | |
| 12442 | std::string response_data; |
| 12443 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 12444 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12445 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12446 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12447 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12448 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12449 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12450 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12451 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12452 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12453 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12454 | ASSERT_TRUE(response); |
| 12455 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12456 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12457 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12458 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12459 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12460 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12461 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12462 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 12463 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12464 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12465 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12466 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12467 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12468 | LoadTimingInfo load_timing_info; |
| 12469 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12470 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12471 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12472 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12473 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12474 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12475 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12476 | HttpRequestInfo request; |
| 12477 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12478 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12479 | request.traffic_annotation = |
| 12480 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12481 | |
| 12482 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12483 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12484 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12485 | MockRead("\r\n"), |
| 12486 | MockRead("hello world"), |
| 12487 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12488 | }; |
| 12489 | |
| 12490 | StaticSocketDataProvider first_transaction( |
| 12491 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12492 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12493 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12494 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12495 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12496 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12497 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12498 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12499 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12500 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12501 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12502 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12503 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12504 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12505 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12506 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12507 | }; |
| 12508 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12509 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12510 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12511 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12512 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 12513 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12514 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12516 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12517 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12518 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12519 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12520 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12521 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12522 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12523 | |
| 12524 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12525 | ASSERT_TRUE(response); |
| 12526 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12527 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12528 | |
| 12529 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12530 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12531 | EXPECT_EQ("hello world", response_data); |
| 12532 | |
| 12533 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12534 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12535 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 12536 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12537 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 12538 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 12539 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12540 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12541 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12542 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12543 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12544 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12545 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12546 | |
| 12547 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12548 | ASSERT_TRUE(response); |
| 12549 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12550 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12551 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12552 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12553 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12554 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12555 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12556 | } |
| 12557 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12558 | // GenerateAuthToken is a mighty big test. |
| 12559 | // It tests all permutation of GenerateAuthToken behavior: |
| 12560 | // - Synchronous and Asynchronous completion. |
| 12561 | // - OK or error on completion. |
| 12562 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 12563 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 12564 | // - Non-authenticating and authenticating backend. |
| 12565 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12566 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12567 | // problems generating an auth token for an authenticating proxy, we don't |
| 12568 | // need to test all permutations of the backend server). |
| 12569 | // |
| 12570 | // The test proceeds by going over each of the configuration cases, and |
| 12571 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 12572 | // specifies both the configuration for the test as well as the expectations |
| 12573 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12574 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12575 | static const char kServer[] = "http://www.example.com"; |
| 12576 | static const char kSecureServer[] = "https://www.example.com"; |
| 12577 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12578 | |
| 12579 | enum AuthTiming { |
| 12580 | AUTH_NONE, |
| 12581 | AUTH_SYNC, |
| 12582 | AUTH_ASYNC, |
| 12583 | }; |
| 12584 | |
| 12585 | const MockWrite kGet( |
| 12586 | "GET / HTTP/1.1\r\n" |
| 12587 | "Host: www.example.com\r\n" |
| 12588 | "Connection: keep-alive\r\n\r\n"); |
| 12589 | const MockWrite kGetProxy( |
| 12590 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12591 | "Host: www.example.com\r\n" |
| 12592 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12593 | const MockWrite kGetAuth( |
| 12594 | "GET / HTTP/1.1\r\n" |
| 12595 | "Host: www.example.com\r\n" |
| 12596 | "Connection: keep-alive\r\n" |
| 12597 | "Authorization: auth_token\r\n\r\n"); |
| 12598 | const MockWrite kGetProxyAuth( |
| 12599 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12600 | "Host: www.example.com\r\n" |
| 12601 | "Proxy-Connection: keep-alive\r\n" |
| 12602 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12603 | const MockWrite kGetAuthThroughProxy( |
| 12604 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12605 | "Host: www.example.com\r\n" |
| 12606 | "Proxy-Connection: keep-alive\r\n" |
| 12607 | "Authorization: auth_token\r\n\r\n"); |
| 12608 | const MockWrite kGetAuthWithProxyAuth( |
| 12609 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12610 | "Host: www.example.com\r\n" |
| 12611 | "Proxy-Connection: keep-alive\r\n" |
| 12612 | "Proxy-Authorization: auth_token\r\n" |
| 12613 | "Authorization: auth_token\r\n\r\n"); |
| 12614 | const MockWrite kConnect( |
| 12615 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12616 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12617 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12618 | const MockWrite kConnectProxyAuth( |
| 12619 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12620 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12621 | "Proxy-Connection: keep-alive\r\n" |
| 12622 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12623 | |
| 12624 | const MockRead kSuccess( |
| 12625 | "HTTP/1.1 200 OK\r\n" |
| 12626 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12627 | "Content-Length: 3\r\n\r\n" |
| 12628 | "Yes"); |
| 12629 | const MockRead kFailure( |
| 12630 | "Should not be called."); |
| 12631 | const MockRead kServerChallenge( |
| 12632 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12633 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12634 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12635 | "Content-Length: 14\r\n\r\n" |
| 12636 | "Unauthorized\r\n"); |
| 12637 | const MockRead kProxyChallenge( |
| 12638 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12639 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 12640 | "Proxy-Connection: close\r\n" |
| 12641 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12642 | "Content-Length: 14\r\n\r\n" |
| 12643 | "Unauthorized\r\n"); |
| 12644 | const MockRead kProxyConnected( |
| 12645 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 12646 | |
| 12647 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 12648 | // no constructors, but the C++ compiler on Windows warns about |
| 12649 | // unspecified data in compound literals. So, moved to using constructors, |
| 12650 | // and TestRound's created with the default constructor should not be used. |
| 12651 | struct TestRound { |
| 12652 | TestRound() |
| 12653 | : expected_rv(ERR_UNEXPECTED), |
| 12654 | extra_write(NULL), |
| 12655 | extra_read(NULL) { |
| 12656 | } |
| 12657 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12658 | int expected_rv_arg) |
| 12659 | : write(write_arg), |
| 12660 | read(read_arg), |
| 12661 | expected_rv(expected_rv_arg), |
| 12662 | extra_write(NULL), |
| 12663 | extra_read(NULL) { |
| 12664 | } |
| 12665 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12666 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 12667 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12668 | : write(write_arg), |
| 12669 | read(read_arg), |
| 12670 | expected_rv(expected_rv_arg), |
| 12671 | extra_write(extra_write_arg), |
| 12672 | extra_read(extra_read_arg) { |
| 12673 | } |
| 12674 | MockWrite write; |
| 12675 | MockRead read; |
| 12676 | int expected_rv; |
| 12677 | const MockWrite* extra_write; |
| 12678 | const MockRead* extra_read; |
| 12679 | }; |
| 12680 | |
| 12681 | static const int kNoSSL = 500; |
| 12682 | |
| 12683 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12684 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12685 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12686 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12687 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12688 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12689 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12690 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12691 | int num_auth_rounds; |
| 12692 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12693 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12694 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12695 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12696 | {__LINE__, |
| 12697 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12698 | AUTH_NONE, |
| 12699 | OK, |
| 12700 | kServer, |
| 12701 | AUTH_NONE, |
| 12702 | OK, |
| 12703 | 1, |
| 12704 | kNoSSL, |
| 12705 | {TestRound(kGet, kSuccess, OK)}}, |
| 12706 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12707 | {__LINE__, |
| 12708 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12709 | AUTH_NONE, |
| 12710 | OK, |
| 12711 | kServer, |
| 12712 | AUTH_SYNC, |
| 12713 | OK, |
| 12714 | 2, |
| 12715 | kNoSSL, |
| 12716 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12717 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12718 | {__LINE__, |
| 12719 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12720 | AUTH_NONE, |
| 12721 | OK, |
| 12722 | kServer, |
| 12723 | AUTH_SYNC, |
| 12724 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12725 | 3, |
| 12726 | kNoSSL, |
| 12727 | {TestRound(kGet, kServerChallenge, OK), |
| 12728 | TestRound(kGet, kServerChallenge, OK), |
| 12729 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12730 | {__LINE__, |
| 12731 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12732 | AUTH_NONE, |
| 12733 | OK, |
| 12734 | kServer, |
| 12735 | AUTH_SYNC, |
| 12736 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12737 | 2, |
| 12738 | kNoSSL, |
| 12739 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12740 | {__LINE__, |
| 12741 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12742 | AUTH_NONE, |
| 12743 | OK, |
| 12744 | kServer, |
| 12745 | AUTH_SYNC, |
| 12746 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 12747 | 2, |
| 12748 | kNoSSL, |
| 12749 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12750 | {__LINE__, |
| 12751 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12752 | AUTH_SYNC, |
| 12753 | ERR_FAILED, |
| 12754 | kServer, |
| 12755 | AUTH_NONE, |
| 12756 | OK, |
| 12757 | 2, |
| 12758 | kNoSSL, |
| 12759 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12760 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12761 | {__LINE__, |
| 12762 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12763 | AUTH_ASYNC, |
| 12764 | ERR_FAILED, |
| 12765 | kServer, |
| 12766 | AUTH_NONE, |
| 12767 | OK, |
| 12768 | 2, |
| 12769 | kNoSSL, |
| 12770 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12771 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12772 | {__LINE__, |
| 12773 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12774 | AUTH_NONE, |
| 12775 | OK, |
| 12776 | kServer, |
| 12777 | AUTH_SYNC, |
| 12778 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12779 | 2, |
| 12780 | kNoSSL, |
| 12781 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12782 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12783 | {__LINE__, |
| 12784 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12785 | AUTH_NONE, |
| 12786 | OK, |
| 12787 | kServer, |
| 12788 | AUTH_ASYNC, |
| 12789 | ERR_FAILED, |
| 12790 | 2, |
| 12791 | kNoSSL, |
| 12792 | {TestRound(kGet, kServerChallenge, OK), |
| 12793 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12794 | {__LINE__, |
| 12795 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12796 | AUTH_NONE, |
| 12797 | OK, |
| 12798 | kServer, |
| 12799 | AUTH_ASYNC, |
| 12800 | OK, |
| 12801 | 2, |
| 12802 | kNoSSL, |
| 12803 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12804 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12805 | {__LINE__, |
| 12806 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12807 | AUTH_NONE, |
| 12808 | OK, |
| 12809 | kServer, |
| 12810 | AUTH_ASYNC, |
| 12811 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12812 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12813 | kNoSSL, |
| 12814 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12815 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12816 | TestRound(kGet, kServerChallenge, OK), |
| 12817 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12818 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12819 | {__LINE__, |
| 12820 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12821 | AUTH_NONE, |
| 12822 | OK, |
| 12823 | kServer, |
| 12824 | AUTH_NONE, |
| 12825 | OK, |
| 12826 | 1, |
| 12827 | kNoSSL, |
| 12828 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12829 | // Authenticating HTTP server through a non-authenticating proxy. |
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_NONE, |
| 12833 | OK, |
| 12834 | kServer, |
| 12835 | AUTH_SYNC, |
| 12836 | OK, |
| 12837 | 2, |
| 12838 | kNoSSL, |
| 12839 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12840 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12841 | {__LINE__, |
| 12842 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12843 | AUTH_NONE, |
| 12844 | OK, |
| 12845 | kServer, |
| 12846 | AUTH_SYNC, |
| 12847 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12848 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12849 | kNoSSL, |
| 12850 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12851 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12852 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12853 | {__LINE__, |
| 12854 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12855 | AUTH_NONE, |
| 12856 | OK, |
| 12857 | kServer, |
| 12858 | AUTH_ASYNC, |
| 12859 | OK, |
| 12860 | 2, |
| 12861 | kNoSSL, |
| 12862 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12863 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12864 | {__LINE__, |
| 12865 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12866 | AUTH_NONE, |
| 12867 | OK, |
| 12868 | kServer, |
| 12869 | AUTH_ASYNC, |
| 12870 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12871 | 2, |
| 12872 | kNoSSL, |
| 12873 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12874 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12875 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12876 | {__LINE__, |
| 12877 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12878 | AUTH_SYNC, |
| 12879 | OK, |
| 12880 | kServer, |
| 12881 | AUTH_NONE, |
| 12882 | OK, |
| 12883 | 2, |
| 12884 | kNoSSL, |
| 12885 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12886 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12887 | {__LINE__, |
| 12888 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12889 | AUTH_SYNC, |
| 12890 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12891 | kServer, |
| 12892 | AUTH_NONE, |
| 12893 | OK, |
| 12894 | 2, |
| 12895 | kNoSSL, |
| 12896 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12897 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12898 | {__LINE__, |
| 12899 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12900 | AUTH_ASYNC, |
| 12901 | OK, |
| 12902 | kServer, |
| 12903 | AUTH_NONE, |
| 12904 | OK, |
| 12905 | 2, |
| 12906 | kNoSSL, |
| 12907 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12908 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12909 | {__LINE__, |
| 12910 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12911 | AUTH_ASYNC, |
| 12912 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12913 | kServer, |
| 12914 | AUTH_NONE, |
| 12915 | OK, |
| 12916 | 2, |
| 12917 | kNoSSL, |
| 12918 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12919 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12920 | {__LINE__, |
| 12921 | kProxy, |
| 12922 | AUTH_ASYNC, |
| 12923 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12924 | kServer, |
| 12925 | AUTH_NONE, |
| 12926 | OK, |
| 12927 | 3, |
| 12928 | kNoSSL, |
| 12929 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12930 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12931 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12932 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12933 | {__LINE__, |
| 12934 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12935 | AUTH_SYNC, |
| 12936 | OK, |
| 12937 | kServer, |
| 12938 | AUTH_SYNC, |
| 12939 | OK, |
| 12940 | 3, |
| 12941 | kNoSSL, |
| 12942 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12943 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12944 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12945 | {__LINE__, |
| 12946 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12947 | AUTH_SYNC, |
| 12948 | OK, |
| 12949 | kServer, |
| 12950 | AUTH_SYNC, |
| 12951 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12952 | 3, |
| 12953 | kNoSSL, |
| 12954 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12955 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12956 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12957 | {__LINE__, |
| 12958 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12959 | AUTH_ASYNC, |
| 12960 | OK, |
| 12961 | kServer, |
| 12962 | AUTH_SYNC, |
| 12963 | OK, |
| 12964 | 3, |
| 12965 | kNoSSL, |
| 12966 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12967 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12968 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12969 | {__LINE__, |
| 12970 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12971 | AUTH_ASYNC, |
| 12972 | OK, |
| 12973 | kServer, |
| 12974 | AUTH_SYNC, |
| 12975 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12976 | 3, |
| 12977 | kNoSSL, |
| 12978 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12979 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12980 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12981 | {__LINE__, |
| 12982 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12983 | AUTH_SYNC, |
| 12984 | OK, |
| 12985 | kServer, |
| 12986 | AUTH_ASYNC, |
| 12987 | OK, |
| 12988 | 3, |
| 12989 | kNoSSL, |
| 12990 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12991 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12992 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12993 | {__LINE__, |
| 12994 | kProxy, |
| 12995 | AUTH_SYNC, |
| 12996 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12997 | kServer, |
| 12998 | AUTH_ASYNC, |
| 12999 | OK, |
| 13000 | 4, |
| 13001 | kNoSSL, |
| 13002 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13003 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13004 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13005 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13006 | {__LINE__, |
| 13007 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13008 | AUTH_SYNC, |
| 13009 | OK, |
| 13010 | kServer, |
| 13011 | AUTH_ASYNC, |
| 13012 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13013 | 3, |
| 13014 | kNoSSL, |
| 13015 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13016 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13017 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13018 | {__LINE__, |
| 13019 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13020 | AUTH_ASYNC, |
| 13021 | OK, |
| 13022 | kServer, |
| 13023 | AUTH_ASYNC, |
| 13024 | OK, |
| 13025 | 3, |
| 13026 | kNoSSL, |
| 13027 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13028 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13029 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13030 | {__LINE__, |
| 13031 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13032 | AUTH_ASYNC, |
| 13033 | OK, |
| 13034 | kServer, |
| 13035 | AUTH_ASYNC, |
| 13036 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13037 | 3, |
| 13038 | kNoSSL, |
| 13039 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13040 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13041 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13042 | {__LINE__, |
| 13043 | kProxy, |
| 13044 | AUTH_ASYNC, |
| 13045 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13046 | kServer, |
| 13047 | AUTH_ASYNC, |
| 13048 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13049 | 4, |
| 13050 | kNoSSL, |
| 13051 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13052 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13053 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13054 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13055 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13056 | {__LINE__, |
| 13057 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13058 | AUTH_NONE, |
| 13059 | OK, |
| 13060 | kSecureServer, |
| 13061 | AUTH_NONE, |
| 13062 | OK, |
| 13063 | 1, |
| 13064 | 0, |
| 13065 | {TestRound(kGet, kSuccess, OK)}}, |
| 13066 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13067 | {__LINE__, |
| 13068 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13069 | AUTH_NONE, |
| 13070 | OK, |
| 13071 | kSecureServer, |
| 13072 | AUTH_SYNC, |
| 13073 | OK, |
| 13074 | 2, |
| 13075 | 0, |
| 13076 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13077 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13078 | {__LINE__, |
| 13079 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13080 | AUTH_NONE, |
| 13081 | OK, |
| 13082 | kSecureServer, |
| 13083 | AUTH_SYNC, |
| 13084 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13085 | 2, |
| 13086 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13087 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13088 | {__LINE__, |
| 13089 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13090 | AUTH_NONE, |
| 13091 | OK, |
| 13092 | kSecureServer, |
| 13093 | AUTH_ASYNC, |
| 13094 | OK, |
| 13095 | 2, |
| 13096 | 0, |
| 13097 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13098 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13099 | {__LINE__, |
| 13100 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13101 | AUTH_NONE, |
| 13102 | OK, |
| 13103 | kSecureServer, |
| 13104 | AUTH_ASYNC, |
| 13105 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13106 | 2, |
| 13107 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13108 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13109 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13110 | {__LINE__, |
| 13111 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13112 | AUTH_NONE, |
| 13113 | OK, |
| 13114 | kSecureServer, |
| 13115 | AUTH_NONE, |
| 13116 | OK, |
| 13117 | 1, |
| 13118 | 0, |
| 13119 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13120 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13121 | {__LINE__, |
| 13122 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13123 | AUTH_NONE, |
| 13124 | OK, |
| 13125 | kSecureServer, |
| 13126 | AUTH_SYNC, |
| 13127 | OK, |
| 13128 | 2, |
| 13129 | 0, |
| 13130 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13131 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13132 | {__LINE__, |
| 13133 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13134 | AUTH_NONE, |
| 13135 | OK, |
| 13136 | kSecureServer, |
| 13137 | AUTH_SYNC, |
| 13138 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13139 | 2, |
| 13140 | 0, |
| 13141 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13142 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13143 | {__LINE__, |
| 13144 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13145 | AUTH_NONE, |
| 13146 | OK, |
| 13147 | kSecureServer, |
| 13148 | AUTH_ASYNC, |
| 13149 | OK, |
| 13150 | 2, |
| 13151 | 0, |
| 13152 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13153 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13154 | {__LINE__, |
| 13155 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13156 | AUTH_NONE, |
| 13157 | OK, |
| 13158 | kSecureServer, |
| 13159 | AUTH_ASYNC, |
| 13160 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13161 | 2, |
| 13162 | 0, |
| 13163 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13164 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13165 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13166 | {__LINE__, |
| 13167 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13168 | AUTH_SYNC, |
| 13169 | OK, |
| 13170 | kSecureServer, |
| 13171 | AUTH_NONE, |
| 13172 | OK, |
| 13173 | 2, |
| 13174 | 1, |
| 13175 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13176 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13177 | {__LINE__, |
| 13178 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13179 | AUTH_SYNC, |
| 13180 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13181 | kSecureServer, |
| 13182 | AUTH_NONE, |
| 13183 | OK, |
| 13184 | 2, |
| 13185 | kNoSSL, |
| 13186 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13187 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13188 | {__LINE__, |
| 13189 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13190 | AUTH_SYNC, |
| 13191 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13192 | kSecureServer, |
| 13193 | AUTH_NONE, |
| 13194 | OK, |
| 13195 | 2, |
| 13196 | kNoSSL, |
| 13197 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13198 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13199 | {__LINE__, |
| 13200 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13201 | AUTH_SYNC, |
| 13202 | ERR_UNEXPECTED, |
| 13203 | kSecureServer, |
| 13204 | AUTH_NONE, |
| 13205 | OK, |
| 13206 | 2, |
| 13207 | kNoSSL, |
| 13208 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13209 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13210 | {__LINE__, |
| 13211 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13212 | AUTH_ASYNC, |
| 13213 | OK, |
| 13214 | kSecureServer, |
| 13215 | AUTH_NONE, |
| 13216 | OK, |
| 13217 | 2, |
| 13218 | 1, |
| 13219 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13220 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13221 | {__LINE__, |
| 13222 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13223 | AUTH_ASYNC, |
| 13224 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13225 | kSecureServer, |
| 13226 | AUTH_NONE, |
| 13227 | OK, |
| 13228 | 2, |
| 13229 | kNoSSL, |
| 13230 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13231 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13232 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13233 | {__LINE__, |
| 13234 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13235 | AUTH_SYNC, |
| 13236 | OK, |
| 13237 | kSecureServer, |
| 13238 | AUTH_SYNC, |
| 13239 | OK, |
| 13240 | 3, |
| 13241 | 1, |
| 13242 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13243 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13244 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13245 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13246 | {__LINE__, |
| 13247 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13248 | AUTH_SYNC, |
| 13249 | OK, |
| 13250 | kSecureServer, |
| 13251 | AUTH_SYNC, |
| 13252 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13253 | 3, |
| 13254 | 1, |
| 13255 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13256 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13257 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13258 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13259 | {__LINE__, |
| 13260 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13261 | AUTH_ASYNC, |
| 13262 | OK, |
| 13263 | kSecureServer, |
| 13264 | AUTH_SYNC, |
| 13265 | OK, |
| 13266 | 3, |
| 13267 | 1, |
| 13268 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13269 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13270 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13271 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13272 | {__LINE__, |
| 13273 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13274 | AUTH_ASYNC, |
| 13275 | OK, |
| 13276 | kSecureServer, |
| 13277 | AUTH_SYNC, |
| 13278 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13279 | 3, |
| 13280 | 1, |
| 13281 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13282 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13283 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13284 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13285 | {__LINE__, |
| 13286 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13287 | AUTH_SYNC, |
| 13288 | OK, |
| 13289 | kSecureServer, |
| 13290 | AUTH_ASYNC, |
| 13291 | OK, |
| 13292 | 3, |
| 13293 | 1, |
| 13294 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13295 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13296 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13297 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13298 | {__LINE__, |
| 13299 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13300 | AUTH_SYNC, |
| 13301 | OK, |
| 13302 | kSecureServer, |
| 13303 | AUTH_ASYNC, |
| 13304 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13305 | 3, |
| 13306 | 1, |
| 13307 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13308 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13309 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13310 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13311 | {__LINE__, |
| 13312 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13313 | AUTH_ASYNC, |
| 13314 | OK, |
| 13315 | kSecureServer, |
| 13316 | AUTH_ASYNC, |
| 13317 | OK, |
| 13318 | 3, |
| 13319 | 1, |
| 13320 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13321 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13322 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13323 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13324 | {__LINE__, |
| 13325 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13326 | AUTH_ASYNC, |
| 13327 | OK, |
| 13328 | kSecureServer, |
| 13329 | AUTH_ASYNC, |
| 13330 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13331 | 3, |
| 13332 | 1, |
| 13333 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13334 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13335 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13336 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13337 | {__LINE__, |
| 13338 | kProxy, |
| 13339 | AUTH_ASYNC, |
| 13340 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13341 | kSecureServer, |
| 13342 | AUTH_ASYNC, |
| 13343 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13344 | 4, |
| 13345 | 2, |
| 13346 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13347 | TestRound(kConnect, kProxyChallenge, OK), |
| 13348 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13349 | &kServerChallenge), |
| 13350 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13351 | }; |
| 13352 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13353 | for (const auto& test_config : test_configs) { |
| 13354 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 13355 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13356 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13357 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13358 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13359 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13360 | |
| 13361 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13362 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13363 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13364 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13365 | std::string auth_challenge = "Mock realm=proxy"; |
| 13366 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13367 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13368 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13369 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13370 | empty_ssl_info, origin, |
| 13371 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13372 | auth_handler->SetGenerateExpectation( |
| 13373 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13374 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13375 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 13376 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13377 | } |
| 13378 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 13379 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13380 | std::string auth_challenge = "Mock realm=server"; |
| 13381 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13382 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13383 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13384 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13385 | empty_ssl_info, origin, |
| 13386 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13387 | auth_handler->SetGenerateExpectation( |
| 13388 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13389 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13390 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13391 | |
| 13392 | // The second handler always succeeds. It should only be used where there |
| 13393 | // are multiple auth sessions for server auth in the same network |
| 13394 | // transaction using the same auth scheme. |
| 13395 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13396 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13397 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 13398 | empty_ssl_info, origin, |
| 13399 | NetLogWithSource()); |
| 13400 | second_handler->SetGenerateExpectation(true, OK); |
| 13401 | auth_factory->AddMockHandler(second_handler.release(), |
| 13402 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13403 | } |
| 13404 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13405 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13406 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 13407 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13408 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13409 | session_deps_.proxy_resolution_service = |
| 13410 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13411 | } |
| 13412 | |
| 13413 | HttpRequestInfo request; |
| 13414 | request.method = "GET"; |
| 13415 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13416 | request.traffic_annotation = |
| 13417 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13418 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13419 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13420 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13421 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 13422 | |
| 13423 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 13424 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13425 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13426 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13427 | const TestRound& read_write_round = test_config.rounds[round]; |
| 13428 | |
| 13429 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13430 | mock_reads.back().push_back(read_write_round.read); |
| 13431 | mock_writes.back().push_back(read_write_round.write); |
| 13432 | |
| 13433 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 13434 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 13435 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13436 | mock_reads.push_back(std::vector<MockRead>()); |
| 13437 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13438 | } |
| 13439 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13440 | if (read_write_round.extra_read) { |
| 13441 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13442 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13443 | if (read_write_round.extra_write) { |
| 13444 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 13445 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13446 | |
| 13447 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13448 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13449 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13450 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13451 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13452 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13453 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13454 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13455 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13456 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13457 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13458 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 13459 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13460 | } |
| 13461 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13462 | // Transaction must be created after DataProviders, so it's destroyed before |
| 13463 | // they are as well. |
| 13464 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13465 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13466 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13467 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13468 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13469 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13470 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13471 | int rv; |
| 13472 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13473 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13474 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13475 | rv = trans.RestartWithAuth( |
| 13476 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13477 | } |
| 13478 | if (rv == ERR_IO_PENDING) |
| 13479 | rv = callback.WaitForResult(); |
| 13480 | |
| 13481 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13482 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13483 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 13484 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13485 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 13486 | continue; |
| 13487 | } |
| 13488 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13489 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13490 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13491 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13492 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13493 | } |
| 13494 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 13495 | } |
| 13496 | } |
| 13497 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13498 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13499 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13500 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13501 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13502 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13503 | session_deps_.proxy_resolution_service = |
| 13504 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13505 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 13506 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13507 | |
| 13508 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13509 | auth_handler->set_connection_based(true); |
| 13510 | std::string auth_challenge = "Mock realm=server"; |
| 13511 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13512 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13513 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13514 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13515 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13516 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13517 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13518 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13519 | int rv = OK; |
| 13520 | const HttpResponseInfo* response = NULL; |
| 13521 | HttpRequestInfo request; |
| 13522 | request.method = "GET"; |
| 13523 | request.url = origin; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13524 | request.traffic_annotation = |
| 13525 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13526 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13527 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13528 | |
| 13529 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 13530 | // to validate that the TCP socket is not released to the pool between |
| 13531 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13532 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13533 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13534 | 50, // Max sockets for pool |
| 13535 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 13536 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 13537 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13538 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 13539 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 13540 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13541 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13542 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13543 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13544 | |
| 13545 | const MockWrite kGet( |
| 13546 | "GET / HTTP/1.1\r\n" |
| 13547 | "Host: www.example.com\r\n" |
| 13548 | "Connection: keep-alive\r\n\r\n"); |
| 13549 | const MockWrite kGetAuth( |
| 13550 | "GET / HTTP/1.1\r\n" |
| 13551 | "Host: www.example.com\r\n" |
| 13552 | "Connection: keep-alive\r\n" |
| 13553 | "Authorization: auth_token\r\n\r\n"); |
| 13554 | |
| 13555 | const MockRead kServerChallenge( |
| 13556 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13557 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13558 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13559 | "Content-Length: 14\r\n\r\n" |
| 13560 | "Unauthorized\r\n"); |
| 13561 | const MockRead kSuccess( |
| 13562 | "HTTP/1.1 200 OK\r\n" |
| 13563 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13564 | "Content-Length: 3\r\n\r\n" |
| 13565 | "Yes"); |
| 13566 | |
| 13567 | MockWrite writes[] = { |
| 13568 | // First round |
| 13569 | kGet, |
| 13570 | // Second round |
| 13571 | kGetAuth, |
| 13572 | // Third round |
| 13573 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13574 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13575 | kGetAuth, |
| 13576 | // Competing request |
| 13577 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13578 | }; |
| 13579 | MockRead reads[] = { |
| 13580 | // First round |
| 13581 | kServerChallenge, |
| 13582 | // Second round |
| 13583 | kServerChallenge, |
| 13584 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13585 | kServerChallenge, |
| 13586 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13587 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13588 | // Competing response |
| 13589 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13590 | }; |
| 13591 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 13592 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13593 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13594 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13595 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13596 | |
| 13597 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13598 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13599 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13600 | if (rv == ERR_IO_PENDING) |
| 13601 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13602 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13603 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13604 | ASSERT_TRUE(response); |
| 13605 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13606 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13607 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13608 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13609 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13610 | // In between rounds, another request comes in for the same domain. |
| 13611 | // It should not be able to grab the TCP socket that trans has already |
| 13612 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13613 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13614 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13615 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 13616 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13617 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13618 | // callback_compete.WaitForResult at this point would stall forever, |
| 13619 | // since the HttpNetworkTransaction does not release the request back to |
| 13620 | // the pool until after authentication completes. |
| 13621 | |
| 13622 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13623 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13624 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13625 | if (rv == ERR_IO_PENDING) |
| 13626 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13627 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13628 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13629 | ASSERT_TRUE(response); |
| 13630 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13631 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13632 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13633 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13634 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13635 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13636 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13637 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13638 | if (rv == ERR_IO_PENDING) |
| 13639 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13640 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13641 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13642 | ASSERT_TRUE(response); |
| 13643 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13644 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13645 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13646 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13647 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13648 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13649 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13650 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13651 | if (rv == ERR_IO_PENDING) |
| 13652 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13653 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13654 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13655 | ASSERT_TRUE(response); |
| 13656 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13657 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13658 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13659 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 13660 | // auth handler should transition to a DONE state in concert with the remote |
| 13661 | // server. But that's not something we can test here with a mock handler. |
| 13662 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 13663 | auth_handler->state()); |
| 13664 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13665 | // Read the body since the fourth round was successful. This will also |
| 13666 | // release the socket back to the pool. |
| 13667 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13668 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13669 | if (rv == ERR_IO_PENDING) |
| 13670 | rv = callback.WaitForResult(); |
| 13671 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13672 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13673 | EXPECT_EQ(0, rv); |
| 13674 | // There are still 0 idle sockets, since the trans_compete transaction |
| 13675 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13676 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13677 | |
| 13678 | // The competing request can now finish. Wait for the headers and then |
| 13679 | // read the body. |
| 13680 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13681 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13682 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13683 | if (rv == ERR_IO_PENDING) |
| 13684 | rv = callback.WaitForResult(); |
| 13685 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13686 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13687 | EXPECT_EQ(0, rv); |
| 13688 | |
| 13689 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13690 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13691 | } |
| 13692 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13693 | // This tests the case that a request is issued via http instead of spdy after |
| 13694 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13695 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13696 | HttpRequestInfo request; |
| 13697 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13698 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13699 | request.traffic_annotation = |
| 13700 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13701 | |
| 13702 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13703 | MockWrite( |
| 13704 | "GET / HTTP/1.1\r\n" |
| 13705 | "Host: www.example.org\r\n" |
| 13706 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13707 | }; |
| 13708 | |
| 13709 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13710 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13711 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13712 | MockRead("\r\n"), |
| 13713 | MockRead("hello world"), |
| 13714 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13715 | }; |
| 13716 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13717 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13718 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13719 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13720 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13721 | |
| 13722 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13723 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13724 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13726 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13730 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13731 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13732 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13733 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13734 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13735 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13736 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13737 | ASSERT_TRUE(response); |
| 13738 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13739 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13740 | |
| 13741 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13742 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13743 | EXPECT_EQ("hello world", response_data); |
| 13744 | |
| 13745 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13746 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13747 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13748 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13749 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 13750 | // immediate server closing of the socket. |
| 13751 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13752 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13753 | HttpRequestInfo request; |
| 13754 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13755 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13756 | request.traffic_annotation = |
| 13757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13758 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13759 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13760 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13761 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13762 | |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 13763 | SpdySerializedFrame req(spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13764 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13765 | |
| 13766 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13767 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13768 | }; |
| 13769 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13770 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13771 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13772 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13773 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13774 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13775 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13778 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13779 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13780 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13781 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13782 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13783 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13784 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 13785 | // it gets it. This is needed since the auth handler may get destroyed |
| 13786 | // before we get a chance to query it. |
| 13787 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 13788 | public: |
| 13789 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 13790 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 13791 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13792 | |
| 13793 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13794 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 13795 | const HttpRequestInfo* request, |
| 13796 | const CompletionCallback& callback, |
| 13797 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13798 | *url_ = request->url; |
| 13799 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 13800 | credentials, request, callback, auth_token); |
| 13801 | } |
| 13802 | |
| 13803 | private: |
| 13804 | GURL* url_; |
| 13805 | }; |
| 13806 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13807 | // Test that if we cancel the transaction as the connection is completing, that |
| 13808 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13809 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13810 | // Setup everything about the connection to complete synchronously, so that |
| 13811 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13812 | // for is the callback from the HttpStreamRequest. |
| 13813 | // Then cancel the transaction. |
| 13814 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13815 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13816 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13817 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13818 | MockRead(SYNCHRONOUS, "hello world"), |
| 13819 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13820 | }; |
| 13821 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13822 | HttpRequestInfo request; |
| 13823 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13824 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13825 | request.traffic_annotation = |
| 13826 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13827 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13828 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13830 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13831 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13832 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13833 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13834 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13835 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13836 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13837 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13838 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13839 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13840 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13841 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13842 | trans.reset(); // Cancel the transaction here. |
| 13843 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13844 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13845 | } |
| 13846 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13847 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13848 | // stream is drained properly and added back to the socket pool. The main |
| 13849 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13850 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13851 | // deleted. |
| 13852 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13853 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13854 | MockRead data_reads[] = { |
| 13855 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13856 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13857 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13858 | MockRead(ASYNC, "1"), |
| 13859 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13860 | // HttpNetworkTransaction has been deleted. |
| 13861 | MockRead(ASYNC, "2"), |
| 13862 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13863 | }; |
| 13864 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13865 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13866 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13867 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13868 | |
| 13869 | { |
| 13870 | HttpRequestInfo request; |
| 13871 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13872 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13873 | request.traffic_annotation = |
| 13874 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13875 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13876 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13877 | TestCompletionCallback callback; |
| 13878 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13879 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13881 | callback.WaitForResult(); |
| 13882 | |
| 13883 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13884 | ASSERT_TRUE(response); |
| 13885 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13886 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13887 | |
| 13888 | // The transaction and HttpRequestInfo are deleted. |
| 13889 | } |
| 13890 | |
| 13891 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13892 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13893 | |
| 13894 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13895 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13896 | } |
| 13897 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13898 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13899 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13900 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13901 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13902 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13903 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13904 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13905 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13906 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13907 | HttpRequestInfo request; |
| 13908 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13909 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13910 | request.traffic_annotation = |
| 13911 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13912 | |
| 13913 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13914 | MockWrite( |
| 13915 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13916 | "Host: www.example.org\r\n" |
| 13917 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13918 | }; |
| 13919 | |
| 13920 | MockRead data_reads1[] = { |
| 13921 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13922 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13923 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13924 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13925 | }; |
| 13926 | |
| 13927 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13928 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13929 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13930 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13931 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13932 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13933 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13934 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13935 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13936 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13937 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13938 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13939 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13941 | |
| 13942 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13943 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13945 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13946 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13947 | |
| 13948 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13949 | EXPECT_EQ(200, response->headers->response_code()); |
| 13950 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13951 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13952 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13953 | HostPortPair::FromString("myproxy:70")), |
| 13954 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13955 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13956 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13957 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13958 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13959 | |
| 13960 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13961 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13962 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13963 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13964 | } |
| 13965 | |
| 13966 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13967 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13968 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13969 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13970 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13971 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13972 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13973 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13974 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13975 | HttpRequestInfo request; |
| 13976 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13977 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13978 | request.traffic_annotation = |
| 13979 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13980 | |
| 13981 | // Since we have proxy, should try to establish tunnel. |
| 13982 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13983 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13984 | "Host: www.example.org:443\r\n" |
| 13985 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13986 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13987 | MockWrite("GET / HTTP/1.1\r\n" |
| 13988 | "Host: www.example.org\r\n" |
| 13989 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13990 | }; |
| 13991 | |
| 13992 | MockRead data_reads1[] = { |
| 13993 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13994 | |
| 13995 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13996 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13997 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13998 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13999 | }; |
| 14000 | |
| 14001 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 14002 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14003 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14004 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14005 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14007 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14008 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14009 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14010 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14011 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14012 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14013 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14014 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14015 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14016 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14017 | |
| 14018 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14019 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14020 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14021 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14022 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14023 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14024 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14025 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14026 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14027 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14028 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14029 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14030 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14031 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14032 | |
| 14033 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14034 | EXPECT_EQ(200, response->headers->response_code()); |
| 14035 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14036 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14037 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14038 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14039 | HostPortPair::FromString("myproxy:70")), |
| 14040 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14041 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14042 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14043 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14044 | |
| 14045 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14046 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14047 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14048 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14049 | } |
| 14050 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14051 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14052 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14053 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14054 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14055 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14056 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14057 | BoundTestNetLog log; |
| 14058 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14059 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14060 | |
| 14061 | HttpRequestInfo request; |
| 14062 | request.method = "GET"; |
| 14063 | request.url = GURL("https://[::1]:443/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14064 | request.traffic_annotation = |
| 14065 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14066 | |
| 14067 | // Since we have proxy, should try to establish tunnel. |
| 14068 | MockWrite data_writes1[] = { |
| 14069 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 14070 | "Host: [::1]:443\r\n" |
| 14071 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14072 | |
| 14073 | MockWrite("GET / HTTP/1.1\r\n" |
| 14074 | "Host: [::1]\r\n" |
| 14075 | "Connection: keep-alive\r\n\r\n"), |
| 14076 | }; |
| 14077 | |
| 14078 | MockRead data_reads1[] = { |
| 14079 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14080 | |
| 14081 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14082 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14083 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14084 | MockRead(SYNCHRONOUS, OK), |
| 14085 | }; |
| 14086 | |
| 14087 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 14088 | data_writes1, arraysize(data_writes1)); |
| 14089 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14090 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14091 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14092 | |
| 14093 | TestCompletionCallback callback1; |
| 14094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14095 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14096 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14097 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14098 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14099 | |
| 14100 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14101 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14102 | TestNetLogEntry::List entries; |
| 14103 | log.GetEntries(&entries); |
| 14104 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14105 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14106 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14107 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14108 | entries, pos, |
| 14109 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14110 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14111 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14112 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14113 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14114 | |
| 14115 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14116 | EXPECT_EQ(200, response->headers->response_code()); |
| 14117 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14118 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14119 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14120 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14121 | HostPortPair::FromString("myproxy:70")), |
| 14122 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14123 | |
| 14124 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14125 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14126 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14127 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14128 | } |
| 14129 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14130 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14131 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14132 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14133 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14134 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14135 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14136 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14137 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14138 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14139 | HttpRequestInfo request; |
| 14140 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14141 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14142 | request.traffic_annotation = |
| 14143 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14144 | |
| 14145 | // Since we have proxy, should try to establish tunnel. |
| 14146 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14147 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14148 | "Host: www.example.org:443\r\n" |
| 14149 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14150 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14151 | MockWrite("GET / HTTP/1.1\r\n" |
| 14152 | "Host: www.example.org\r\n" |
| 14153 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14154 | }; |
| 14155 | |
| 14156 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14157 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14158 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14159 | }; |
| 14160 | |
| 14161 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 14162 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14163 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14164 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14165 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14166 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14167 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14168 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14169 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14170 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14171 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14172 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14173 | |
| 14174 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14175 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14176 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14177 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14178 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14179 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14180 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14181 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14182 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14183 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14184 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14185 | } |
| 14186 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14187 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14188 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14189 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14190 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14191 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14192 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14193 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14194 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14195 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14196 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14197 | }; |
| 14198 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14199 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 14200 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14201 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14202 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14203 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14204 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14205 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14206 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14207 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14208 | |
| 14209 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14210 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14211 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 14212 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14213 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14214 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14215 | |
| 14216 | HttpRequestInfo request; |
| 14217 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14218 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14219 | request.traffic_annotation = |
| 14220 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14221 | |
| 14222 | // This is the important line that marks this as a preconnect. |
| 14223 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 14224 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14225 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14226 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14227 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14228 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14229 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14230 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14231 | } |
| 14232 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14233 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14234 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14235 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14236 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14237 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14238 | request_info.url = GURL("https://www.example.com/"); |
| 14239 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14240 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14241 | request_info.traffic_annotation = |
| 14242 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14243 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14244 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14245 | MockWrite data_writes[] = { |
| 14246 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14247 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14248 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14249 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14250 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14251 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14252 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14253 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14255 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14256 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14257 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14258 | rv = callback.WaitForResult(); |
| 14259 | ASSERT_EQ(error, rv); |
| 14260 | } |
| 14261 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14262 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14263 | // Just check a grab bag of cert errors. |
| 14264 | static const int kErrors[] = { |
| 14265 | ERR_CERT_COMMON_NAME_INVALID, |
| 14266 | ERR_CERT_AUTHORITY_INVALID, |
| 14267 | ERR_CERT_DATE_INVALID, |
| 14268 | }; |
| 14269 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14270 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 14271 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14272 | } |
| 14273 | } |
| 14274 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14275 | // Ensure that a client certificate is removed from the SSL client auth |
| 14276 | // cache when: |
| 14277 | // 1) No proxy is involved. |
| 14278 | // 2) TLS False Start is disabled. |
| 14279 | // 3) The initial TLS handshake requests a client certificate. |
| 14280 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14281 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14282 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14283 | request_info.url = GURL("https://www.example.com/"); |
| 14284 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14285 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14286 | request_info.traffic_annotation = |
| 14287 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14288 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14289 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14290 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14291 | |
| 14292 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 14293 | // CertificateRequest is received for the first time, the handshake will |
| 14294 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14295 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14296 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14297 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14298 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14299 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14300 | |
| 14301 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 14302 | // False Start is not being used, the result of the SSL handshake will be |
| 14303 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 14304 | // matches the result of a server sending a handshake_failure alert, |
| 14305 | // rather than a Finished message, because it requires a client |
| 14306 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14307 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14308 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14309 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14310 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14311 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14312 | |
| 14313 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 14314 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14315 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 14316 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14317 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14318 | // requiring a client certificate, this fallback handshake should also |
| 14319 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14320 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14321 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14322 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14323 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14324 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14325 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14326 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 14327 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14328 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 14329 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14330 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14331 | // requiring a client certificate, this fallback handshake should also |
| 14332 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14333 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14334 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14335 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14336 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14337 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14338 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14339 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14340 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14341 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14342 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14343 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14344 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14345 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14346 | |
| 14347 | // Complete the SSL handshake, which should abort due to requiring a |
| 14348 | // client certificate. |
| 14349 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14350 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14351 | |
| 14352 | // Indicate that no certificate should be supplied. From the perspective |
| 14353 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14354 | // certificate, so this is the same as supply a |
| 14355 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14356 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14357 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14358 | |
| 14359 | // Ensure the certificate was added to the client auth cache before |
| 14360 | // allowing the connection to continue restarting. |
| 14361 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14362 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14363 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14364 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14365 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14366 | |
| 14367 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14368 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14369 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14370 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14371 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14372 | |
| 14373 | // Ensure that the client certificate is removed from the cache on a |
| 14374 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14375 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14376 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14377 | } |
| 14378 | |
| 14379 | // Ensure that a client certificate is removed from the SSL client auth |
| 14380 | // cache when: |
| 14381 | // 1) No proxy is involved. |
| 14382 | // 2) TLS False Start is enabled. |
| 14383 | // 3) The initial TLS handshake requests a client certificate. |
| 14384 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14385 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14386 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14387 | request_info.url = GURL("https://www.example.com/"); |
| 14388 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14389 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14390 | request_info.traffic_annotation = |
| 14391 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14392 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14393 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14394 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14395 | |
| 14396 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 14397 | // return successfully after reading up to the peer's Certificate message. |
| 14398 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 14399 | // enqueue application data to be sent in the same packet as the |
| 14400 | // ChangeCipherSpec and Finished messages. |
| 14401 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 14402 | // called, which expects to process the peer's ChangeCipherSpec and |
| 14403 | // Finished messages. If there was an error negotiating with the peer, |
| 14404 | // such as due to the peer requiring a client certificate when none was |
| 14405 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 14406 | // called. |
| 14407 | |
| 14408 | // Like the non-False Start case, when a client certificate is requested by |
| 14409 | // the peer, the handshake is aborted during the Connect() call. |
| 14410 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14411 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14412 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14413 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14414 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14415 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14416 | |
| 14417 | // When a client certificate is supplied, Connect() will not be aborted |
| 14418 | // when the peer requests the certificate. Instead, the handshake will |
| 14419 | // artificially succeed, allowing the caller to write the HTTP request to |
| 14420 | // the socket. The handshake messages are not processed until Read() is |
| 14421 | // called, which then detects that the handshake was aborted, due to the |
| 14422 | // peer sending a handshake_failure because it requires a client |
| 14423 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14424 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14425 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14426 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14427 | MockRead data2_reads[] = { |
| 14428 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14429 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14430 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14431 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14432 | |
| 14433 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14434 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 14435 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14436 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14437 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14438 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14439 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14440 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14441 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14442 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 14443 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14444 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14445 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14446 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14447 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14448 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14449 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14450 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14451 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14452 | ssl_data5.cert_request_info = cert_request.get(); |
| 14453 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14454 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14455 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 14456 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14457 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14458 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14459 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14460 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14461 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14462 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14463 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14464 | |
| 14465 | // Complete the SSL handshake, which should abort due to requiring a |
| 14466 | // client certificate. |
| 14467 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14468 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14469 | |
| 14470 | // Indicate that no certificate should be supplied. From the perspective |
| 14471 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14472 | // certificate, so this is the same as supply a |
| 14473 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14474 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14475 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14476 | |
| 14477 | // Ensure the certificate was added to the client auth cache before |
| 14478 | // allowing the connection to continue restarting. |
| 14479 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14480 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14481 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14482 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14483 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14484 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14485 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14486 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14487 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14488 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14489 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14490 | |
| 14491 | // Ensure that the client certificate is removed from the cache on a |
| 14492 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14493 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14494 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14495 | } |
| 14496 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14497 | // Ensure that a client certificate is removed from the SSL client auth |
| 14498 | // cache when: |
| 14499 | // 1) An HTTPS proxy is involved. |
| 14500 | // 3) The HTTPS proxy requests a client certificate. |
| 14501 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 14502 | // proxy. |
| 14503 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 14504 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14505 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14506 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14507 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14508 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14509 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14510 | |
| 14511 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14512 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14513 | |
| 14514 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 14515 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 14516 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 14517 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14518 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14519 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14520 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14521 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14522 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14523 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14524 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14525 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14526 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14527 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14528 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14529 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14530 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 14531 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14532 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14533 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14534 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14535 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14536 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14537 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14538 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14539 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14540 | requests[0].url = GURL("https://www.example.com/"); |
| 14541 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14542 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14543 | requests[0].traffic_annotation = |
| 14544 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14545 | |
| 14546 | requests[1].url = GURL("http://www.example.com/"); |
| 14547 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14548 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14549 | requests[1].traffic_annotation = |
| 14550 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14551 | |
| 14552 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14553 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14554 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14555 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14556 | |
| 14557 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14558 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14559 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14560 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14561 | |
| 14562 | // Complete the SSL handshake, which should abort due to requiring a |
| 14563 | // client certificate. |
| 14564 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14565 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14566 | |
| 14567 | // Indicate that no certificate should be supplied. From the perspective |
| 14568 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14569 | // certificate, so this is the same as supply a |
| 14570 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14571 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14572 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14573 | |
| 14574 | // Ensure the certificate was added to the client auth cache before |
| 14575 | // allowing the connection to continue restarting. |
| 14576 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14577 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14578 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14579 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14580 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14581 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 14582 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14583 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14584 | HostPortPair("www.example.com", 443), &client_cert, |
| 14585 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14586 | |
| 14587 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 14588 | // then consume ssl_data3, which should also fail. The result code is |
| 14589 | // checked against what ssl_data3 should return. |
| 14590 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14591 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14592 | |
| 14593 | // Now that the new handshake has failed, ensure that the client |
| 14594 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14595 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14596 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14597 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14598 | HostPortPair("www.example.com", 443), &client_cert, |
| 14599 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14600 | } |
| 14601 | } |
| 14602 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14603 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14604 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14605 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14606 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14607 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14608 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14609 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14610 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14611 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14612 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14613 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14614 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14615 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14616 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14617 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14618 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14619 | SpdySerializedFrame host1_resp_body( |
| 14620 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14621 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14622 | SpdySerializedFrame host2_resp_body( |
| 14623 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14624 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14625 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14626 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14627 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14628 | }; |
| 14629 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14630 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14631 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14632 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14633 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14634 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14635 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14636 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14637 | HttpRequestInfo request1; |
| 14638 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14639 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14640 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14641 | request1.traffic_annotation = |
| 14642 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14643 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14644 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14645 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14646 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14647 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14648 | |
| 14649 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14650 | ASSERT_TRUE(response); |
| 14651 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14652 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14653 | |
| 14654 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14655 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14656 | EXPECT_EQ("hello!", response_data); |
| 14657 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14658 | // Preload mail.example.com into HostCache. |
| 14659 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 14660 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14661 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14662 | std::unique_ptr<HostResolver::Request> request; |
| 14663 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14664 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14665 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14666 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14667 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14668 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14669 | |
| 14670 | HttpRequestInfo request2; |
| 14671 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14672 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14673 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14674 | request2.traffic_annotation = |
| 14675 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14676 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14677 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14678 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14679 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14680 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14681 | |
| 14682 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14683 | ASSERT_TRUE(response); |
| 14684 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14685 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14686 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14687 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14688 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14689 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14690 | } |
| 14691 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14692 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14693 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14694 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14695 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14696 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14697 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14698 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14699 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14700 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14701 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14702 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14703 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14704 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14705 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14706 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14707 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14708 | SpdySerializedFrame host1_resp_body( |
| 14709 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14710 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14711 | SpdySerializedFrame host2_resp_body( |
| 14712 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14713 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14714 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14715 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14716 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14717 | }; |
| 14718 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14719 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14720 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14721 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14722 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14723 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14724 | |
| 14725 | TestCompletionCallback callback; |
| 14726 | HttpRequestInfo request1; |
| 14727 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14728 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14729 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14730 | request1.traffic_annotation = |
| 14731 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14732 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14733 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14734 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14735 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14736 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14737 | |
| 14738 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14739 | ASSERT_TRUE(response); |
| 14740 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14741 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14742 | |
| 14743 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14744 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14745 | EXPECT_EQ("hello!", response_data); |
| 14746 | |
| 14747 | HttpRequestInfo request2; |
| 14748 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14749 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14750 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14751 | request2.traffic_annotation = |
| 14752 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14753 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14754 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14755 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14757 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14758 | |
| 14759 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14760 | ASSERT_TRUE(response); |
| 14761 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14762 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14763 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14764 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14765 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14766 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14767 | } |
| 14768 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14769 | // Regression test for https://crbug.com/546991. |
| 14770 | // The server might not be able to serve an IP pooled request, and might send a |
| 14771 | // 421 Misdirected Request response status to indicate this. |
| 14772 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 14773 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 14774 | // Two hosts resolve to the same IP address. |
| 14775 | const std::string ip_addr = "1.2.3.4"; |
| 14776 | IPAddress ip; |
| 14777 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14778 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14779 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14780 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14781 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14782 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14783 | |
| 14784 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14785 | |
| 14786 | // Two requests on the first connection. |
| 14787 | SpdySerializedFrame req1( |
| 14788 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14789 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14790 | SpdySerializedFrame req2( |
| 14791 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14792 | SpdySerializedFrame rst( |
| 14793 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14794 | MockWrite writes1[] = { |
| 14795 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14796 | CreateMockWrite(rst, 6), |
| 14797 | }; |
| 14798 | |
| 14799 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14800 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14801 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14802 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14803 | response_headers[kHttp2StatusHeader] = "421"; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14804 | SpdySerializedFrame resp2( |
| 14805 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 14806 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14807 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14808 | |
| 14809 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14810 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14811 | arraysize(writes1)); |
| 14812 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14813 | |
| 14814 | AddSSLSocketData(); |
| 14815 | |
| 14816 | // Retry the second request on a second connection. |
| 14817 | SpdyTestUtil spdy_util2; |
| 14818 | SpdySerializedFrame req3( |
| 14819 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14820 | MockWrite writes2[] = { |
| 14821 | CreateMockWrite(req3, 0), |
| 14822 | }; |
| 14823 | |
| 14824 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14825 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14826 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14827 | MockRead(ASYNC, 0, 3)}; |
| 14828 | |
| 14829 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14830 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14831 | arraysize(writes2)); |
| 14832 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14833 | |
| 14834 | AddSSLSocketData(); |
| 14835 | |
| 14836 | // Preload mail.example.org into HostCache. |
| 14837 | HostPortPair host_port("mail.example.org", 443); |
| 14838 | HostResolver::RequestInfo resolve_info(host_port); |
| 14839 | AddressList ignored; |
| 14840 | std::unique_ptr<HostResolver::Request> request; |
| 14841 | TestCompletionCallback callback; |
| 14842 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14843 | &ignored, callback.callback(), |
| 14844 | &request, NetLogWithSource()); |
| 14845 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14846 | rv = callback.WaitForResult(); |
| 14847 | EXPECT_THAT(rv, IsOk()); |
| 14848 | |
| 14849 | HttpRequestInfo request1; |
| 14850 | request1.method = "GET"; |
| 14851 | request1.url = GURL("https://www.example.org/"); |
| 14852 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14853 | request1.traffic_annotation = |
| 14854 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14855 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14856 | |
| 14857 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14859 | rv = callback.WaitForResult(); |
| 14860 | EXPECT_THAT(rv, IsOk()); |
| 14861 | |
| 14862 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14863 | ASSERT_TRUE(response); |
| 14864 | ASSERT_TRUE(response->headers); |
| 14865 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14866 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14867 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14868 | std::string response_data; |
| 14869 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14870 | EXPECT_EQ("hello!", response_data); |
| 14871 | |
| 14872 | HttpRequestInfo request2; |
| 14873 | request2.method = "GET"; |
| 14874 | request2.url = GURL("https://mail.example.org/"); |
| 14875 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14876 | request2.traffic_annotation = |
| 14877 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14878 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14879 | |
| 14880 | BoundTestNetLog log; |
| 14881 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14882 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14883 | rv = callback.WaitForResult(); |
| 14884 | EXPECT_THAT(rv, IsOk()); |
| 14885 | |
| 14886 | response = trans2.GetResponseInfo(); |
| 14887 | ASSERT_TRUE(response); |
| 14888 | ASSERT_TRUE(response->headers); |
| 14889 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14890 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14891 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14892 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14893 | EXPECT_EQ("hello!", response_data); |
| 14894 | |
| 14895 | TestNetLogEntry::List entries; |
| 14896 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14897 | ExpectLogContainsSomewhere( |
| 14898 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14899 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14900 | } |
| 14901 | |
| 14902 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14903 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14904 | // portions of the response. |
| 14905 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14906 | // Two hosts resolve to the same IP address. |
| 14907 | const std::string ip_addr = "1.2.3.4"; |
| 14908 | IPAddress ip; |
| 14909 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14910 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14911 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14912 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14913 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14914 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14915 | |
| 14916 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14917 | |
| 14918 | // Two requests on the first connection. |
| 14919 | SpdySerializedFrame req1( |
| 14920 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14921 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14922 | SpdySerializedFrame req2( |
| 14923 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14924 | SpdySerializedFrame rst( |
| 14925 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14926 | MockWrite writes1[] = { |
| 14927 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14928 | CreateMockWrite(rst, 6), |
| 14929 | }; |
| 14930 | |
| 14931 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14932 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14933 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14934 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14935 | response_headers[kHttp2StatusHeader] = "421"; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14936 | SpdySerializedFrame resp2( |
| 14937 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14938 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14939 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14940 | |
| 14941 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14942 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14943 | arraysize(writes1)); |
| 14944 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14945 | |
| 14946 | AddSSLSocketData(); |
| 14947 | |
| 14948 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14949 | // Retry again. |
| 14950 | SpdyTestUtil spdy_util2; |
| 14951 | SpdySerializedFrame req3( |
| 14952 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14953 | MockWrite writes2[] = { |
| 14954 | CreateMockWrite(req3, 0), |
| 14955 | }; |
| 14956 | |
| 14957 | SpdySerializedFrame resp3( |
| 14958 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 14959 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14960 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14961 | MockRead(ASYNC, 0, 3)}; |
| 14962 | |
| 14963 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14964 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14965 | arraysize(writes2)); |
| 14966 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14967 | |
| 14968 | AddSSLSocketData(); |
| 14969 | |
| 14970 | // Preload mail.example.org into HostCache. |
| 14971 | HostPortPair host_port("mail.example.org", 443); |
| 14972 | HostResolver::RequestInfo resolve_info(host_port); |
| 14973 | AddressList ignored; |
| 14974 | std::unique_ptr<HostResolver::Request> request; |
| 14975 | TestCompletionCallback callback; |
| 14976 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14977 | &ignored, callback.callback(), |
| 14978 | &request, NetLogWithSource()); |
| 14979 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14980 | rv = callback.WaitForResult(); |
| 14981 | EXPECT_THAT(rv, IsOk()); |
| 14982 | |
| 14983 | HttpRequestInfo request1; |
| 14984 | request1.method = "GET"; |
| 14985 | request1.url = GURL("https://www.example.org/"); |
| 14986 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14987 | request1.traffic_annotation = |
| 14988 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14989 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14990 | |
| 14991 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14993 | rv = callback.WaitForResult(); |
| 14994 | EXPECT_THAT(rv, IsOk()); |
| 14995 | |
| 14996 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14997 | ASSERT_TRUE(response); |
| 14998 | ASSERT_TRUE(response->headers); |
| 14999 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15000 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15001 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15002 | std::string response_data; |
| 15003 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15004 | EXPECT_EQ("hello!", response_data); |
| 15005 | |
| 15006 | HttpRequestInfo request2; |
| 15007 | request2.method = "GET"; |
| 15008 | request2.url = GURL("https://mail.example.org/"); |
| 15009 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15010 | request2.traffic_annotation = |
| 15011 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15012 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15013 | |
| 15014 | BoundTestNetLog log; |
| 15015 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15016 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15017 | rv = callback.WaitForResult(); |
| 15018 | EXPECT_THAT(rv, IsOk()); |
| 15019 | |
| 15020 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15021 | // caller. |
| 15022 | response = trans2.GetResponseInfo(); |
| 15023 | ASSERT_TRUE(response); |
| 15024 | ASSERT_TRUE(response->headers); |
| 15025 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15026 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15027 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15028 | EXPECT_TRUE(response->ssl_info.cert); |
| 15029 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15030 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15031 | } |
| 15032 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15033 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15034 | public: |
| 15035 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15036 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15037 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15038 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15039 | int ResolveFromCache(const RequestInfo& info, |
| 15040 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15041 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15042 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 15043 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15044 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15045 | return rv; |
| 15046 | } |
| 15047 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15048 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15049 | const HostPortPair host_port_; |
| 15050 | }; |
| 15051 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15052 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15053 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15054 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15055 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15056 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15057 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15058 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15059 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15060 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15061 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15062 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15063 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15064 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15065 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15066 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15067 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15068 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15069 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15070 | SpdySerializedFrame host1_resp_body( |
| 15071 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15072 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15073 | SpdySerializedFrame host2_resp_body( |
| 15074 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15075 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15076 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15077 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15078 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15079 | }; |
| 15080 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15081 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15082 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15083 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 15084 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15085 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15086 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15087 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15088 | HttpRequestInfo request1; |
| 15089 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15090 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15091 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15092 | request1.traffic_annotation = |
| 15093 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15094 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15095 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15096 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15098 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15099 | |
| 15100 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15101 | ASSERT_TRUE(response); |
| 15102 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15103 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15104 | |
| 15105 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15106 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15107 | EXPECT_EQ("hello!", response_data); |
| 15108 | |
| 15109 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15110 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15111 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15112 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15113 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15114 | &ignored, callback.callback(), |
| 15115 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15117 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15118 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15119 | |
| 15120 | HttpRequestInfo request2; |
| 15121 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15122 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15123 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15124 | request2.traffic_annotation = |
| 15125 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15126 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15127 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15128 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15129 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15130 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15131 | |
| 15132 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15133 | ASSERT_TRUE(response); |
| 15134 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15135 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15136 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15137 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15138 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15139 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15140 | } |
| 15141 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15142 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15143 | const std::string https_url = "https://www.example.org:8080/"; |
| 15144 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15145 | |
| 15146 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15147 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15148 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15149 | |
| 15150 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15151 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15152 | }; |
| 15153 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15154 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15155 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15156 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15157 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15158 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15159 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15160 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15161 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15162 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15163 | |
| 15164 | // HTTP GET for the HTTP URL |
| 15165 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15166 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15167 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15168 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15169 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15170 | }; |
| 15171 | |
| 15172 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15173 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15174 | MockRead(ASYNC, 2, "hello"), |
| 15175 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15176 | }; |
| 15177 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15178 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15179 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15180 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15181 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15182 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15183 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15184 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15185 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15186 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15187 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15188 | |
| 15189 | // Start the first transaction to set up the SpdySession |
| 15190 | HttpRequestInfo request1; |
| 15191 | request1.method = "GET"; |
| 15192 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15193 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15194 | request1.traffic_annotation = |
| 15195 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15196 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15197 | TestCompletionCallback callback1; |
| 15198 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15199 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15200 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15201 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15202 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15203 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15204 | |
| 15205 | // Now, start the HTTP request |
| 15206 | HttpRequestInfo request2; |
| 15207 | request2.method = "GET"; |
| 15208 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15209 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15210 | request2.traffic_annotation = |
| 15211 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15212 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15213 | TestCompletionCallback callback2; |
| 15214 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15215 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15216 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15217 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15218 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15219 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15220 | } |
| 15221 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15222 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15223 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15224 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15225 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15226 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15227 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15228 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15229 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15230 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15231 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15232 | |
| 15233 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15234 | // negotiated. |
| 15235 | StaticSocketDataProvider data; |
| 15236 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15237 | |
| 15238 | // 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] | 15239 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15240 | // mocked. This way the request relies on the alternate Job. |
| 15241 | StaticSocketDataProvider data_refused; |
| 15242 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15243 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15244 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15245 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15246 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15247 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15248 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15249 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15250 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15251 | http_server_properties->SetHttp2AlternativeService( |
| 15252 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15253 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15254 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15255 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15256 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15257 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15258 | request.traffic_annotation = |
| 15259 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15260 | TestCompletionCallback callback; |
| 15261 | |
| 15262 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15263 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15264 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15265 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15266 | } |
| 15267 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15268 | // 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] | 15269 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15270 | // succeeds, the request should succeed, even if the latter fails because |
| 15271 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15272 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15273 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15274 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15275 | |
| 15276 | // Negotiate HTTP/1.1 with alternative. |
| 15277 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15278 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15279 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 15280 | |
| 15281 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15282 | // negotiated. |
| 15283 | StaticSocketDataProvider data; |
| 15284 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15285 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15286 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15287 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15288 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15289 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 15290 | |
| 15291 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15292 | MockWrite("GET / HTTP/1.1\r\n" |
| 15293 | "Host: www.example.org\r\n" |
| 15294 | "Connection: keep-alive\r\n\r\n"), |
| 15295 | MockWrite("GET /second HTTP/1.1\r\n" |
| 15296 | "Host: www.example.org\r\n" |
| 15297 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15298 | }; |
| 15299 | |
| 15300 | MockRead http_reads[] = { |
| 15301 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15302 | MockRead("Content-Type: text/html\r\n"), |
| 15303 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15304 | MockRead("foobar"), |
| 15305 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15306 | MockRead("Content-Type: text/html\r\n"), |
| 15307 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15308 | MockRead("another"), |
| 15309 | }; |
| 15310 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15311 | http_writes, arraysize(http_writes)); |
| 15312 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15313 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15314 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15315 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15316 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15317 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15318 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15319 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15320 | http_server_properties->SetHttp2AlternativeService( |
| 15321 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15322 | |
| 15323 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15324 | HttpRequestInfo request1; |
| 15325 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15326 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15327 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15328 | request1.traffic_annotation = |
| 15329 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15330 | TestCompletionCallback callback1; |
| 15331 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15332 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15333 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15334 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15335 | |
| 15336 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15337 | ASSERT_TRUE(response1); |
| 15338 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15339 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 15340 | |
| 15341 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15342 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15343 | EXPECT_EQ("foobar", response_data1); |
| 15344 | |
| 15345 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 15346 | // for alternative service. |
| 15347 | EXPECT_TRUE( |
| 15348 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 15349 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15350 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15351 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15352 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15353 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15354 | HttpRequestInfo request2; |
| 15355 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15356 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15357 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15358 | request2.traffic_annotation = |
| 15359 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15360 | TestCompletionCallback callback2; |
| 15361 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15362 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15363 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15364 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15365 | |
| 15366 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15367 | ASSERT_TRUE(response2); |
| 15368 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15369 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 15370 | |
| 15371 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15372 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15373 | EXPECT_EQ("another", response_data2); |
| 15374 | } |
| 15375 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15376 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 15377 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 15378 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15379 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15380 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15381 | HostPortPair alternative("alternative.example.org", 443); |
| 15382 | std::string origin_url = "https://origin.example.org:443"; |
| 15383 | std::string alternative_url = "https://alternative.example.org:443"; |
| 15384 | |
| 15385 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 15386 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15387 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15389 | |
| 15390 | // HTTP/1.1 data for |request1| and |request2|. |
| 15391 | MockWrite http_writes[] = { |
| 15392 | MockWrite( |
| 15393 | "GET / HTTP/1.1\r\n" |
| 15394 | "Host: alternative.example.org\r\n" |
| 15395 | "Connection: keep-alive\r\n\r\n"), |
| 15396 | MockWrite( |
| 15397 | "GET / HTTP/1.1\r\n" |
| 15398 | "Host: alternative.example.org\r\n" |
| 15399 | "Connection: keep-alive\r\n\r\n"), |
| 15400 | }; |
| 15401 | |
| 15402 | MockRead http_reads[] = { |
| 15403 | MockRead( |
| 15404 | "HTTP/1.1 200 OK\r\n" |
| 15405 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15406 | "Content-Length: 40\r\n\r\n" |
| 15407 | "first HTTP/1.1 response from alternative"), |
| 15408 | MockRead( |
| 15409 | "HTTP/1.1 200 OK\r\n" |
| 15410 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15411 | "Content-Length: 41\r\n\r\n" |
| 15412 | "second HTTP/1.1 response from alternative"), |
| 15413 | }; |
| 15414 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15415 | http_writes, arraysize(http_writes)); |
| 15416 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15417 | |
| 15418 | // This test documents that an alternate Job should not pool to an already |
| 15419 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15420 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15421 | StaticSocketDataProvider data_refused; |
| 15422 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15423 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15424 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15425 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15426 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15427 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15428 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15429 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15430 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15431 | http_server_properties->SetHttp2AlternativeService( |
| 15432 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15433 | |
| 15434 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15435 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15436 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15437 | request1.method = "GET"; |
| 15438 | request1.url = GURL(alternative_url); |
| 15439 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15440 | request1.traffic_annotation = |
| 15441 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15442 | TestCompletionCallback callback1; |
| 15443 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15444 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15445 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15446 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15447 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15448 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15449 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15450 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15451 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 15452 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15453 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15454 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 15455 | |
| 15456 | // Request for origin.example.org, which has an alternative service. This |
| 15457 | // will start two Jobs: the alternative looks for connections to pool to, |
| 15458 | // 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] | 15459 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15460 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15461 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15462 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15463 | request2.method = "GET"; |
| 15464 | request2.url = GURL(origin_url); |
| 15465 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15466 | request2.traffic_annotation = |
| 15467 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15468 | TestCompletionCallback callback2; |
| 15469 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15470 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15471 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15472 | |
| 15473 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 15474 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15475 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15476 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15477 | request3.method = "GET"; |
| 15478 | request3.url = GURL(alternative_url); |
| 15479 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15480 | request3.traffic_annotation = |
| 15481 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15482 | TestCompletionCallback callback3; |
| 15483 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15484 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15485 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15486 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15487 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15488 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15489 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15490 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15491 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 15492 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15493 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15494 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 15495 | } |
| 15496 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15497 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15498 | const std::string https_url = "https://www.example.org:8080/"; |
| 15499 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15500 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15501 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15502 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15503 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15504 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15505 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15506 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15507 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15508 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15509 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15510 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15511 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 15512 | |
| 15513 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 15514 | SpdyHeaderBlock req2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 15515 | req2_block[kHttp2MethodHeader] = "GET"; |
| 15516 | req2_block[kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 15517 | req2_block[kHttp2SchemeHeader] = "http"; |
| 15518 | req2_block[kHttp2PathHeader] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15519 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15520 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15521 | |
| 15522 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15523 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 15524 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15525 | }; |
| 15526 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15527 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15528 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15529 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15530 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15531 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 15532 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15533 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15534 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15535 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15536 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15537 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15538 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15539 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15540 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15541 | CreateMockRead(wrapped_resp1, 4), |
| 15542 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15543 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15544 | CreateMockRead(resp2, 8), |
| 15545 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15546 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 15547 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15548 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15549 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15550 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15551 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15552 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15553 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15554 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15555 | ProxyResolutionService::CreateFixedFromPacResult( |
| 15556 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15557 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15558 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15559 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15560 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15561 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15562 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15563 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15564 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15565 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15566 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15567 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15568 | |
| 15569 | // Start the first transaction to set up the SpdySession |
| 15570 | HttpRequestInfo request1; |
| 15571 | request1.method = "GET"; |
| 15572 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15573 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15574 | request1.traffic_annotation = |
| 15575 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15576 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15577 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15578 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15579 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15580 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15581 | data1.RunUntilPaused(); |
| 15582 | base::RunLoop().RunUntilIdle(); |
| 15583 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15584 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15585 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15586 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15587 | LoadTimingInfo load_timing_info1; |
| 15588 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 15589 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 15590 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15591 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15592 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15593 | HttpRequestInfo request2; |
| 15594 | request2.method = "GET"; |
| 15595 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15596 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15597 | request2.traffic_annotation = |
| 15598 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15599 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15600 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15601 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15602 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15603 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15604 | data1.RunUntilPaused(); |
| 15605 | base::RunLoop().RunUntilIdle(); |
| 15606 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15607 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15608 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15609 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15610 | |
| 15611 | LoadTimingInfo load_timing_info2; |
| 15612 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 15613 | // The established SPDY sessions is considered reused by the HTTP request. |
| 15614 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 15615 | // HTTP requests over a SPDY session should have a different connection |
| 15616 | // socket_log_id than requests over a tunnel. |
| 15617 | 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] | 15618 | } |
| 15619 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15620 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 15621 | // that we do not pool other origins that resolve to the same IP when |
| 15622 | // the certificate does not match the new origin. |
| 15623 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15624 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15625 | const std::string url1 = "http://www.example.org/"; |
| 15626 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15627 | const std::string ip_addr = "1.2.3.4"; |
| 15628 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15629 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15630 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15631 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15632 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 15633 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15634 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15635 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15636 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15637 | |
| 15638 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15639 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15640 | }; |
| 15641 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15642 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15643 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15644 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15645 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 15646 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15647 | }; |
| 15648 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15649 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15650 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 15651 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 15652 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15653 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15654 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15655 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15656 | |
| 15657 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15658 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15659 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15660 | |
| 15661 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15662 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15663 | }; |
| 15664 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15665 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15666 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 15667 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15668 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15669 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15670 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15671 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15672 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15673 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15674 | |
| 15675 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 15676 | // all others direct. |
| 15677 | ProxyConfig proxy_config; |
| 15678 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15679 | session_deps_.proxy_resolution_service = |
| 15680 | std::make_unique<ProxyResolutionService>( |
| 15681 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 15682 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 15683 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15684 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15685 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15686 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15687 | // Load a valid cert. Note, that this does not need to |
| 15688 | // be valid for proxy because the MockSSLClientSocket does |
| 15689 | // not actually verify it. But SpdySession will use this |
| 15690 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 15691 | ssl1.ssl_info.cert = |
| 15692 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 15693 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15694 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15695 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15696 | |
| 15697 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15698 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15699 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15700 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15701 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15702 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15703 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15704 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15705 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15706 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15707 | |
| 15708 | // Start the first transaction to set up the SpdySession |
| 15709 | HttpRequestInfo request1; |
| 15710 | request1.method = "GET"; |
| 15711 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15712 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15713 | request1.traffic_annotation = |
| 15714 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15715 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15716 | TestCompletionCallback callback1; |
| 15717 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15718 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15719 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15720 | data1.RunUntilPaused(); |
| 15721 | base::RunLoop().RunUntilIdle(); |
| 15722 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15723 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15724 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15725 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15726 | |
| 15727 | // Now, start the HTTP request |
| 15728 | HttpRequestInfo request2; |
| 15729 | request2.method = "GET"; |
| 15730 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15731 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15732 | request2.traffic_annotation = |
| 15733 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15734 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15735 | TestCompletionCallback callback2; |
| 15736 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15737 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15738 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15739 | |
| 15740 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15741 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15742 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15743 | } |
| 15744 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15745 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 15746 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 15747 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 15748 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15749 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15750 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15751 | |
| 15752 | MockRead reads1[] = { |
| 15753 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 15754 | }; |
| 15755 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15756 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15757 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15758 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15759 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15760 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15761 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15762 | }; |
| 15763 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15764 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15765 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15766 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15767 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 15768 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15769 | }; |
| 15770 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15771 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15772 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15773 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15774 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15775 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15777 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15778 | |
| 15779 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15780 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15781 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15782 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15783 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15784 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15785 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15786 | |
| 15787 | // Start the first transaction to set up the SpdySession and verify that |
| 15788 | // connection was closed. |
| 15789 | HttpRequestInfo request1; |
| 15790 | request1.method = "GET"; |
| 15791 | request1.url = GURL(https_url); |
| 15792 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15793 | request1.traffic_annotation = |
| 15794 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15795 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15796 | TestCompletionCallback callback1; |
| 15797 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15798 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15799 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15800 | |
| 15801 | // Now, start the second request and make sure it succeeds. |
| 15802 | HttpRequestInfo request2; |
| 15803 | request2.method = "GET"; |
| 15804 | request2.url = GURL(https_url); |
| 15805 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15806 | request2.traffic_annotation = |
| 15807 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15808 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15809 | TestCompletionCallback callback2; |
| 15810 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15811 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15812 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15813 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15814 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15815 | } |
| 15816 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15817 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15818 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15819 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15820 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15821 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15822 | |
| 15823 | // Use two different hosts with different IPs so they don't get pooled. |
| 15824 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 15825 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15826 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15827 | |
| 15828 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15829 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15830 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15831 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15832 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15833 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15834 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15835 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15836 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15837 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15838 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15839 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15840 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15841 | SpdySerializedFrame host1_resp_body( |
| 15842 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15843 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15844 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15845 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15846 | }; |
| 15847 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15848 | // Use a separate test instance for the separate SpdySession that will be |
| 15849 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15850 | SpdyTestUtil spdy_util_2; |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15851 | SequencedSocketData spdy1_data(spdy1_reads, arraysize(spdy1_reads), |
| 15852 | spdy1_writes, arraysize(spdy1_writes)); |
| 15853 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15854 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15855 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15856 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15857 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15858 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15859 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15860 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15861 | SpdySerializedFrame host2_resp_body( |
| 15862 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15863 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15864 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15865 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15866 | }; |
| 15867 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15868 | SequencedSocketData spdy2_data(spdy2_reads, arraysize(spdy2_reads), |
| 15869 | spdy2_writes, arraysize(spdy2_writes)); |
| 15870 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15871 | |
| 15872 | MockWrite http_write[] = { |
| 15873 | MockWrite("GET / HTTP/1.1\r\n" |
| 15874 | "Host: www.a.com\r\n" |
| 15875 | "Connection: keep-alive\r\n\r\n"), |
| 15876 | }; |
| 15877 | |
| 15878 | MockRead http_read[] = { |
| 15879 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15880 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15881 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15882 | MockRead("hello!"), |
| 15883 | }; |
| 15884 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 15885 | http_write, arraysize(http_write)); |
| 15886 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15887 | |
| 15888 | HostPortPair host_port_pair_a("www.a.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15889 | SpdySessionKey spdy_session_key_a(host_port_pair_a, ProxyServer::Direct(), |
| 15890 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15891 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15892 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15893 | |
| 15894 | TestCompletionCallback callback; |
| 15895 | HttpRequestInfo request1; |
| 15896 | request1.method = "GET"; |
| 15897 | request1.url = GURL("https://www.a.com/"); |
| 15898 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15899 | request1.traffic_annotation = |
| 15900 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15901 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15902 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15903 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15904 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15905 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15906 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15907 | |
| 15908 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15909 | ASSERT_TRUE(response); |
| 15910 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15911 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15912 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15913 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15914 | |
| 15915 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15916 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15917 | EXPECT_EQ("hello!", response_data); |
| 15918 | trans.reset(); |
| 15919 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15920 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15921 | |
| 15922 | HostPortPair host_port_pair_b("www.b.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15923 | SpdySessionKey spdy_session_key_b(host_port_pair_b, ProxyServer::Direct(), |
| 15924 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15925 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15926 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15927 | HttpRequestInfo request2; |
| 15928 | request2.method = "GET"; |
| 15929 | request2.url = GURL("https://www.b.com/"); |
| 15930 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15931 | request2.traffic_annotation = |
| 15932 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15933 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15934 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15935 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15936 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15937 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15938 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15939 | |
| 15940 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15941 | ASSERT_TRUE(response); |
| 15942 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15943 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15944 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15945 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15946 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15947 | EXPECT_EQ("hello!", response_data); |
| 15948 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15949 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15950 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15951 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15952 | |
| 15953 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15954 | SpdySessionKey spdy_session_key_a1(host_port_pair_a1, ProxyServer::Direct(), |
| 15955 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15956 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15957 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15958 | HttpRequestInfo request3; |
| 15959 | request3.method = "GET"; |
| 15960 | request3.url = GURL("http://www.a.com/"); |
| 15961 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15962 | request3.traffic_annotation = |
| 15963 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15964 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15965 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15966 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15967 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15968 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15969 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15970 | |
| 15971 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15972 | ASSERT_TRUE(response); |
| 15973 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15974 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15975 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15976 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15977 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15978 | EXPECT_EQ("hello!", response_data); |
| 15979 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15980 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15981 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15982 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15983 | } |
| 15984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15985 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15986 | HttpRequestInfo request; |
| 15987 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15988 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15989 | request.traffic_annotation = |
| 15990 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15991 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15992 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15993 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15994 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15995 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15996 | StaticSocketDataProvider data; |
| 15997 | data.set_connect_data(mock_connect); |
| 15998 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15999 | |
| 16000 | TestCompletionCallback callback; |
| 16001 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16002 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16003 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16004 | |
| 16005 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16006 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16007 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16008 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16009 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16010 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16011 | |
| 16012 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16013 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16014 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16015 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16016 | |
| 16017 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16018 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16019 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16020 | } |
| 16021 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16022 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16023 | HttpRequestInfo request; |
| 16024 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16025 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16026 | request.traffic_annotation = |
| 16027 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16028 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16029 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16030 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16031 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16032 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16033 | StaticSocketDataProvider data; |
| 16034 | data.set_connect_data(mock_connect); |
| 16035 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16036 | |
| 16037 | TestCompletionCallback callback; |
| 16038 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16039 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16040 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16041 | |
| 16042 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16043 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16044 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16045 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16046 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16047 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16048 | |
| 16049 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16050 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16051 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16052 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16053 | |
| 16054 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16055 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16056 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16057 | } |
| 16058 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16059 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16060 | HttpRequestInfo request; |
| 16061 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16062 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16063 | request.traffic_annotation = |
| 16064 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16065 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16066 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16067 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16068 | |
| 16069 | MockWrite data_writes[] = { |
| 16070 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16071 | }; |
| 16072 | MockRead data_reads[] = { |
| 16073 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16074 | }; |
| 16075 | |
| 16076 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16077 | data_writes, arraysize(data_writes)); |
| 16078 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16079 | |
| 16080 | TestCompletionCallback callback; |
| 16081 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16082 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16083 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16084 | |
| 16085 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16086 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16087 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16088 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16089 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16090 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16091 | } |
| 16092 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16093 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16094 | HttpRequestInfo request; |
| 16095 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16096 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16097 | request.traffic_annotation = |
| 16098 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16099 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16100 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16101 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16102 | |
| 16103 | MockWrite data_writes[] = { |
| 16104 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16105 | }; |
| 16106 | MockRead data_reads[] = { |
| 16107 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16108 | }; |
| 16109 | |
| 16110 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16111 | data_writes, arraysize(data_writes)); |
| 16112 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16113 | |
| 16114 | TestCompletionCallback callback; |
| 16115 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16116 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16117 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16118 | |
| 16119 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16120 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16121 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16122 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16123 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16124 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16125 | } |
| 16126 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16127 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16128 | HttpRequestInfo request; |
| 16129 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16130 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16131 | request.traffic_annotation = |
| 16132 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16133 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16134 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16135 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16136 | |
| 16137 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16138 | MockWrite( |
| 16139 | "GET / HTTP/1.1\r\n" |
| 16140 | "Host: www.example.org\r\n" |
| 16141 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16142 | }; |
| 16143 | MockRead data_reads[] = { |
| 16144 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16145 | }; |
| 16146 | |
| 16147 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16148 | data_writes, arraysize(data_writes)); |
| 16149 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16150 | |
| 16151 | TestCompletionCallback callback; |
| 16152 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16153 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16154 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16155 | |
| 16156 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16157 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16158 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16159 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16160 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16161 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16162 | } |
| 16163 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16164 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16165 | HttpRequestInfo request; |
| 16166 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16167 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16168 | request.traffic_annotation = |
| 16169 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16170 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16171 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16172 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16173 | |
| 16174 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16175 | MockWrite( |
| 16176 | "GET / HTTP/1.1\r\n" |
| 16177 | "Host: www.example.org\r\n" |
| 16178 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16179 | }; |
| 16180 | MockRead data_reads[] = { |
| 16181 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16182 | }; |
| 16183 | |
| 16184 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16185 | data_writes, arraysize(data_writes)); |
| 16186 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16187 | |
| 16188 | TestCompletionCallback callback; |
| 16189 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16190 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16191 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16192 | |
| 16193 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16194 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16195 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16196 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16197 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16198 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16199 | } |
| 16200 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16201 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16202 | HttpRequestInfo request; |
| 16203 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16204 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16205 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16206 | request.traffic_annotation = |
| 16207 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16208 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16209 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16210 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16211 | |
| 16212 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16213 | MockWrite( |
| 16214 | "GET / HTTP/1.1\r\n" |
| 16215 | "Host: www.example.org\r\n" |
| 16216 | "Connection: keep-alive\r\n" |
| 16217 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16218 | }; |
| 16219 | MockRead data_reads[] = { |
| 16220 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16221 | "Content-Length: 5\r\n\r\n" |
| 16222 | "hello"), |
| 16223 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16224 | }; |
| 16225 | |
| 16226 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16227 | data_writes, arraysize(data_writes)); |
| 16228 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16229 | |
| 16230 | TestCompletionCallback callback; |
| 16231 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16232 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16233 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16234 | |
| 16235 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16236 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16237 | |
| 16238 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16239 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16240 | std::string foo; |
| 16241 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 16242 | EXPECT_EQ("bar", foo); |
| 16243 | } |
| 16244 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16245 | namespace { |
| 16246 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 16247 | // Fake HttpStream that simply records calls to SetPriority(). |
| 16248 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16249 | public base::SupportsWeakPtr<FakeStream> { |
| 16250 | public: |
| 16251 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16252 | ~FakeStream() override = default; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16253 | |
| 16254 | RequestPriority priority() const { return priority_; } |
| 16255 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16256 | int InitializeStream(const HttpRequestInfo* request_info, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 16257 | bool can_send_early, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16258 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16259 | const NetLogWithSource& net_log, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16260 | CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16261 | return ERR_IO_PENDING; |
| 16262 | } |
| 16263 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16264 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 16265 | HttpResponseInfo* response, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16266 | CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16267 | ADD_FAILURE(); |
| 16268 | return ERR_UNEXPECTED; |
| 16269 | } |
| 16270 | |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16271 | int ReadResponseHeaders(CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16272 | ADD_FAILURE(); |
| 16273 | return ERR_UNEXPECTED; |
| 16274 | } |
| 16275 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16276 | int ReadResponseBody(IOBuffer* buf, |
| 16277 | int buf_len, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16278 | CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16279 | ADD_FAILURE(); |
| 16280 | return ERR_UNEXPECTED; |
| 16281 | } |
| 16282 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16283 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16284 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16285 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16286 | ADD_FAILURE(); |
| 16287 | return false; |
| 16288 | } |
| 16289 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16290 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16291 | ADD_FAILURE(); |
| 16292 | return false; |
| 16293 | } |
| 16294 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16295 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16296 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 16297 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16298 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 16299 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 16300 | ADD_FAILURE(); |
| 16301 | return 0; |
| 16302 | } |
| 16303 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 16304 | int64_t GetTotalSentBytes() const override { |
| 16305 | ADD_FAILURE(); |
| 16306 | return 0; |
| 16307 | } |
| 16308 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16309 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16310 | ADD_FAILURE(); |
| 16311 | return false; |
| 16312 | } |
| 16313 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 16314 | bool GetAlternativeService( |
| 16315 | AlternativeService* alternative_service) const override { |
| 16316 | ADD_FAILURE(); |
| 16317 | return false; |
| 16318 | } |
| 16319 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16320 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 16321 | |
| 16322 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16323 | ADD_FAILURE(); |
| 16324 | } |
| 16325 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16326 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 16327 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 16328 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 16329 | TokenBindingType tb_type, |
| 16330 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16331 | ADD_FAILURE(); |
| 16332 | return ERR_NOT_IMPLEMENTED; |
| 16333 | } |
| 16334 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16335 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16336 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 16337 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 16338 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16339 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16340 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 16341 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 16342 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 16343 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 16344 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16345 | private: |
| 16346 | RequestPriority priority_; |
| 16347 | |
| 16348 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 16349 | }; |
| 16350 | |
| 16351 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 16352 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16353 | class FakeStreamRequest : public HttpStreamRequest, |
| 16354 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 16355 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16356 | FakeStreamRequest(RequestPriority priority, |
| 16357 | HttpStreamRequest::Delegate* delegate) |
| 16358 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16359 | delegate_(delegate), |
| 16360 | websocket_stream_create_helper_(NULL) {} |
| 16361 | |
| 16362 | FakeStreamRequest(RequestPriority priority, |
| 16363 | HttpStreamRequest::Delegate* delegate, |
| 16364 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 16365 | : priority_(priority), |
| 16366 | delegate_(delegate), |
| 16367 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16368 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16369 | ~FakeStreamRequest() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16370 | |
| 16371 | RequestPriority priority() const { return priority_; } |
| 16372 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16373 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 16374 | websocket_stream_create_helper() const { |
| 16375 | return websocket_stream_create_helper_; |
| 16376 | } |
| 16377 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16378 | // Create a new FakeStream and pass it to the request's |
| 16379 | // delegate. Returns a weak pointer to the FakeStream. |
| 16380 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16381 | auto fake_stream = std::make_unique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16382 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 16383 | // immediately delete |fake_stream|. |
| 16384 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 16385 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16386 | return weak_stream; |
| 16387 | } |
| 16388 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 16389 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16390 | ADD_FAILURE(); |
| 16391 | return ERR_UNEXPECTED; |
| 16392 | } |
| 16393 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16394 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16395 | ADD_FAILURE(); |
| 16396 | return LoadState(); |
| 16397 | } |
| 16398 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16399 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16400 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16401 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16402 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 16403 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16404 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16405 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16406 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16407 | const ConnectionAttempts& connection_attempts() const override { |
| 16408 | static ConnectionAttempts no_attempts; |
| 16409 | return no_attempts; |
| 16410 | } |
| 16411 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16412 | private: |
| 16413 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16414 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16415 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16416 | |
| 16417 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 16418 | }; |
| 16419 | |
| 16420 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 16421 | class FakeStreamFactory : public HttpStreamFactory { |
| 16422 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16423 | FakeStreamFactory() = default; |
| 16424 | ~FakeStreamFactory() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16425 | |
| 16426 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 16427 | // RequestStream() (which may be NULL if it was destroyed already). |
| 16428 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 16429 | return last_stream_request_; |
| 16430 | } |
| 16431 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16432 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 16433 | const HttpRequestInfo& info, |
| 16434 | RequestPriority priority, |
| 16435 | const SSLConfig& server_ssl_config, |
| 16436 | const SSLConfig& proxy_ssl_config, |
| 16437 | HttpStreamRequest::Delegate* delegate, |
| 16438 | bool enable_ip_based_pooling, |
| 16439 | bool enable_alternative_services, |
| 16440 | const NetLogWithSource& net_log) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16441 | auto fake_request = std::make_unique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16442 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16443 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16444 | } |
| 16445 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16446 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 16447 | const HttpRequestInfo& info, |
| 16448 | RequestPriority priority, |
| 16449 | const SSLConfig& server_ssl_config, |
| 16450 | const SSLConfig& proxy_ssl_config, |
| 16451 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16452 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 16453 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16454 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 16455 | NOTREACHED(); |
| 16456 | return nullptr; |
| 16457 | } |
| 16458 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16459 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16460 | const HttpRequestInfo& info, |
| 16461 | RequestPriority priority, |
| 16462 | const SSLConfig& server_ssl_config, |
| 16463 | const SSLConfig& proxy_ssl_config, |
| 16464 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 16465 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16466 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 16467 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16468 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16469 | auto fake_request = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16470 | std::make_unique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16471 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16472 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16473 | } |
| 16474 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16475 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16476 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16477 | ADD_FAILURE(); |
| 16478 | } |
| 16479 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16480 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16481 | ADD_FAILURE(); |
| 16482 | return NULL; |
| 16483 | } |
| 16484 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 16485 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 16486 | const std::string& parent_absolute_name) const override { |
| 16487 | ADD_FAILURE(); |
| 16488 | } |
| 16489 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16490 | private: |
| 16491 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 16492 | |
| 16493 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 16494 | }; |
| 16495 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16496 | } // namespace |
| 16497 | |
| 16498 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 16499 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16500 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16501 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16502 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16503 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16504 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16505 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16506 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16507 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16508 | |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16509 | request.traffic_annotation = |
| 16510 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16511 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16512 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16513 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16514 | TestCompletionCallback callback; |
| 16515 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16516 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16517 | |
| 16518 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16519 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16520 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16521 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16522 | } |
| 16523 | |
| 16524 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16525 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16526 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16527 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16528 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16529 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16530 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16531 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16532 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16533 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16534 | |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16535 | request.traffic_annotation = |
| 16536 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16537 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16538 | TestCompletionCallback callback; |
| 16539 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16540 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16541 | |
| 16542 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16543 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16544 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16545 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16546 | |
| 16547 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16548 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16549 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 16550 | } |
| 16551 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16552 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16553 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16554 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16555 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16556 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16557 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16558 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16559 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16560 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16561 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16562 | |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16563 | request.traffic_annotation = |
| 16564 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16565 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16566 | TestCompletionCallback callback; |
| 16567 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16568 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16569 | |
| 16570 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16571 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16572 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16573 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16574 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16575 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 16576 | |
| 16577 | trans.SetPriority(LOWEST); |
| 16578 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 16579 | } |
| 16580 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16581 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16582 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16583 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16584 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16585 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16586 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16587 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16588 | |
| 16589 | // Set up SSL request. |
| 16590 | |
| 16591 | HttpRequestInfo ssl_request; |
| 16592 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16593 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16594 | ssl_request.traffic_annotation = |
| 16595 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16596 | |
| 16597 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16598 | MockWrite( |
| 16599 | "GET / HTTP/1.1\r\n" |
| 16600 | "Host: www.example.org\r\n" |
| 16601 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16602 | }; |
| 16603 | MockRead ssl_reads[] = { |
| 16604 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16605 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16606 | MockRead("hello world"), |
| 16607 | MockRead(SYNCHRONOUS, OK), |
| 16608 | }; |
| 16609 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 16610 | ssl_writes, arraysize(ssl_writes)); |
| 16611 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16612 | |
| 16613 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16614 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16615 | |
| 16616 | // Set up HTTP request. |
| 16617 | |
| 16618 | HttpRequestInfo http_request; |
| 16619 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16620 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16621 | http_request.traffic_annotation = |
| 16622 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16623 | |
| 16624 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16625 | MockWrite( |
| 16626 | "GET / HTTP/1.1\r\n" |
| 16627 | "Host: www.example.org\r\n" |
| 16628 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16629 | }; |
| 16630 | MockRead http_reads[] = { |
| 16631 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16632 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16633 | MockRead("falafel"), |
| 16634 | MockRead(SYNCHRONOUS, OK), |
| 16635 | }; |
| 16636 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16637 | http_writes, arraysize(http_writes)); |
| 16638 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16639 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16640 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16641 | |
| 16642 | // Start the SSL request. |
| 16643 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16644 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16645 | ASSERT_EQ(ERR_IO_PENDING, |
| 16646 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 16647 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16648 | |
| 16649 | // Start the HTTP request. Pool should stall. |
| 16650 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16651 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16652 | ASSERT_EQ(ERR_IO_PENDING, |
| 16653 | http_trans.Start(&http_request, http_callback.callback(), |
| 16654 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16655 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16656 | |
| 16657 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16658 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16659 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16660 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16661 | EXPECT_EQ("hello world", response_data); |
| 16662 | |
| 16663 | // The SSL socket should automatically be closed, so the HTTP request can |
| 16664 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16665 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 16666 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16667 | |
| 16668 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16669 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16670 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16671 | EXPECT_EQ("falafel", response_data); |
| 16672 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16673 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16674 | } |
| 16675 | |
| 16676 | // Tests that when a SSL connection is established but there's no corresponding |
| 16677 | // request that needs it, the new socket is closed if the transport socket pool |
| 16678 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16679 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16680 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16681 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16682 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16683 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16684 | |
| 16685 | // Set up an ssl request. |
| 16686 | |
| 16687 | HttpRequestInfo ssl_request; |
| 16688 | ssl_request.method = "GET"; |
| 16689 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16690 | ssl_request.traffic_annotation = |
| 16691 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16692 | |
| 16693 | // No data will be sent on the SSL socket. |
| 16694 | StaticSocketDataProvider ssl_data; |
| 16695 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16696 | |
| 16697 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16698 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16699 | |
| 16700 | // Set up HTTP request. |
| 16701 | |
| 16702 | HttpRequestInfo http_request; |
| 16703 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16704 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16705 | http_request.traffic_annotation = |
| 16706 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16707 | |
| 16708 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16709 | MockWrite( |
| 16710 | "GET / HTTP/1.1\r\n" |
| 16711 | "Host: www.example.org\r\n" |
| 16712 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16713 | }; |
| 16714 | MockRead http_reads[] = { |
| 16715 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16716 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16717 | MockRead("falafel"), |
| 16718 | MockRead(SYNCHRONOUS, OK), |
| 16719 | }; |
| 16720 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16721 | http_writes, arraysize(http_writes)); |
| 16722 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16723 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16724 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16725 | |
| 16726 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 16727 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16728 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16729 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16730 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16731 | |
| 16732 | // Start the HTTP request. Pool should stall. |
| 16733 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16734 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16735 | ASSERT_EQ(ERR_IO_PENDING, |
| 16736 | http_trans.Start(&http_request, http_callback.callback(), |
| 16737 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16738 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16739 | |
| 16740 | // The SSL connection will automatically be closed once the connection is |
| 16741 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16742 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16743 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16744 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16745 | EXPECT_EQ("falafel", response_data); |
| 16746 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16747 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16748 | } |
| 16749 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16750 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16751 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16752 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16753 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16754 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16755 | |
| 16756 | HttpRequestInfo request; |
| 16757 | request.method = "POST"; |
| 16758 | request.url = GURL("http://www.foo.com/"); |
| 16759 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16760 | request.traffic_annotation = |
| 16761 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16762 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16764 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16765 | // Send headers successfully, but get an error while sending the body. |
| 16766 | MockWrite data_writes[] = { |
| 16767 | MockWrite("POST / HTTP/1.1\r\n" |
| 16768 | "Host: www.foo.com\r\n" |
| 16769 | "Connection: keep-alive\r\n" |
| 16770 | "Content-Length: 3\r\n\r\n"), |
| 16771 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16772 | }; |
| 16773 | |
| 16774 | MockRead data_reads[] = { |
| 16775 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16776 | MockRead("hello world"), |
| 16777 | MockRead(SYNCHRONOUS, OK), |
| 16778 | }; |
| 16779 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16780 | arraysize(data_writes)); |
| 16781 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16782 | |
| 16783 | TestCompletionCallback callback; |
| 16784 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16785 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16786 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16787 | |
| 16788 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16789 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16790 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16791 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16792 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16793 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16794 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16795 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16796 | |
| 16797 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16798 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16799 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16800 | EXPECT_EQ("hello world", response_data); |
| 16801 | } |
| 16802 | |
| 16803 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16804 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16805 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16806 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16807 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16808 | MockWrite data_writes[] = { |
| 16809 | MockWrite("GET / HTTP/1.1\r\n" |
| 16810 | "Host: www.foo.com\r\n" |
| 16811 | "Connection: keep-alive\r\n\r\n"), |
| 16812 | MockWrite("POST / HTTP/1.1\r\n" |
| 16813 | "Host: www.foo.com\r\n" |
| 16814 | "Connection: keep-alive\r\n" |
| 16815 | "Content-Length: 3\r\n\r\n"), |
| 16816 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16817 | }; |
| 16818 | |
| 16819 | MockRead data_reads[] = { |
| 16820 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16821 | "Content-Length: 14\r\n\r\n"), |
| 16822 | MockRead("first response"), |
| 16823 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16824 | "Content-Length: 15\r\n\r\n"), |
| 16825 | MockRead("second response"), |
| 16826 | MockRead(SYNCHRONOUS, OK), |
| 16827 | }; |
| 16828 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16829 | arraysize(data_writes)); |
| 16830 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16831 | |
| 16832 | TestCompletionCallback callback; |
| 16833 | HttpRequestInfo request1; |
| 16834 | request1.method = "GET"; |
| 16835 | request1.url = GURL("http://www.foo.com/"); |
| 16836 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16837 | request1.traffic_annotation = |
| 16838 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16839 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16840 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16841 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16842 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16843 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16844 | |
| 16845 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16846 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16847 | |
| 16848 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16849 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16850 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16851 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16852 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16853 | |
| 16854 | std::string response_data1; |
| 16855 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16856 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16857 | EXPECT_EQ("first response", response_data1); |
| 16858 | // Delete the transaction to release the socket back into the socket pool. |
| 16859 | trans1.reset(); |
| 16860 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16861 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16862 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16863 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16864 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16865 | |
| 16866 | HttpRequestInfo request2; |
| 16867 | request2.method = "POST"; |
| 16868 | request2.url = GURL("http://www.foo.com/"); |
| 16869 | request2.upload_data_stream = &upload_data_stream; |
| 16870 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16871 | request2.traffic_annotation = |
| 16872 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16873 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16874 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16875 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16876 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16877 | |
| 16878 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16879 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16880 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16881 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16882 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16883 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16884 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16885 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16886 | |
| 16887 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16888 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16889 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16890 | EXPECT_EQ("second response", response_data2); |
| 16891 | } |
| 16892 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16893 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16894 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16895 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16896 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16897 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16898 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16899 | |
| 16900 | HttpRequestInfo request; |
| 16901 | request.method = "POST"; |
| 16902 | request.url = GURL("http://www.foo.com/"); |
| 16903 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16904 | request.traffic_annotation = |
| 16905 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16906 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16907 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16908 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16909 | // Send headers successfully, but get an error while sending the body. |
| 16910 | MockWrite data_writes[] = { |
| 16911 | MockWrite("POST / HTTP/1.1\r\n" |
| 16912 | "Host: www.foo.com\r\n" |
| 16913 | "Connection: keep-alive\r\n" |
| 16914 | "Content-Length: 3\r\n\r\n" |
| 16915 | "fo"), |
| 16916 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16917 | }; |
| 16918 | |
| 16919 | MockRead data_reads[] = { |
| 16920 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16921 | MockRead("hello world"), |
| 16922 | MockRead(SYNCHRONOUS, OK), |
| 16923 | }; |
| 16924 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16925 | arraysize(data_writes)); |
| 16926 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16927 | |
| 16928 | TestCompletionCallback callback; |
| 16929 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16930 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16932 | |
| 16933 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16934 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16935 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16936 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16937 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16938 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16939 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16940 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16941 | |
| 16942 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16943 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16944 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16945 | EXPECT_EQ("hello world", response_data); |
| 16946 | } |
| 16947 | |
| 16948 | // This tests the more common case than the previous test, where headers and |
| 16949 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16950 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16951 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16952 | |
| 16953 | HttpRequestInfo request; |
| 16954 | request.method = "POST"; |
| 16955 | request.url = GURL("http://www.foo.com/"); |
| 16956 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16957 | request.traffic_annotation = |
| 16958 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16959 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16960 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16961 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16962 | // Send headers successfully, but get an error while sending the body. |
| 16963 | MockWrite data_writes[] = { |
| 16964 | MockWrite("POST / HTTP/1.1\r\n" |
| 16965 | "Host: www.foo.com\r\n" |
| 16966 | "Connection: keep-alive\r\n" |
| 16967 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16968 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16969 | }; |
| 16970 | |
| 16971 | MockRead data_reads[] = { |
| 16972 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16973 | MockRead("hello world"), |
| 16974 | MockRead(SYNCHRONOUS, OK), |
| 16975 | }; |
| 16976 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16977 | arraysize(data_writes)); |
| 16978 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16979 | |
| 16980 | TestCompletionCallback callback; |
| 16981 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16982 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16984 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16985 | // they can't be merged with the body in a single send. Not currently |
| 16986 | // necessary since a chunked body is never merged with headers, but this makes |
| 16987 | // the test more future proof. |
| 16988 | base::RunLoop().RunUntilIdle(); |
| 16989 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16990 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16991 | |
| 16992 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16993 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16994 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16995 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16996 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16997 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16998 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16999 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17000 | |
| 17001 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17002 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17003 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17004 | EXPECT_EQ("hello world", response_data); |
| 17005 | } |
| 17006 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17007 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17008 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17009 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17010 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17011 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17012 | |
| 17013 | HttpRequestInfo request; |
| 17014 | request.method = "POST"; |
| 17015 | request.url = GURL("http://www.foo.com/"); |
| 17016 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17017 | request.traffic_annotation = |
| 17018 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17019 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17020 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17021 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17022 | |
| 17023 | MockWrite data_writes[] = { |
| 17024 | MockWrite("POST / HTTP/1.1\r\n" |
| 17025 | "Host: www.foo.com\r\n" |
| 17026 | "Connection: keep-alive\r\n" |
| 17027 | "Content-Length: 3\r\n\r\n"), |
| 17028 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17029 | }; |
| 17030 | |
| 17031 | MockRead data_reads[] = { |
| 17032 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17033 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17034 | MockRead("hello world"), |
| 17035 | MockRead(SYNCHRONOUS, OK), |
| 17036 | }; |
| 17037 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17038 | arraysize(data_writes)); |
| 17039 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17040 | |
| 17041 | TestCompletionCallback callback; |
| 17042 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17043 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17044 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17045 | |
| 17046 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17047 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17048 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17049 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17050 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17051 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17052 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17053 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17054 | |
| 17055 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17056 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17057 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17058 | EXPECT_EQ("hello world", response_data); |
| 17059 | } |
| 17060 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17061 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17062 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17063 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17064 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17065 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17066 | |
| 17067 | HttpRequestInfo request; |
| 17068 | request.method = "POST"; |
| 17069 | request.url = GURL("http://www.foo.com/"); |
| 17070 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17071 | request.traffic_annotation = |
| 17072 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17073 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17074 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17075 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17076 | // Send headers successfully, but get an error while sending the body. |
| 17077 | MockWrite data_writes[] = { |
| 17078 | MockWrite("POST / HTTP/1.1\r\n" |
| 17079 | "Host: www.foo.com\r\n" |
| 17080 | "Connection: keep-alive\r\n" |
| 17081 | "Content-Length: 3\r\n\r\n"), |
| 17082 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17083 | }; |
| 17084 | |
| 17085 | MockRead data_reads[] = { |
| 17086 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17087 | MockRead("hello world"), |
| 17088 | MockRead(SYNCHRONOUS, OK), |
| 17089 | }; |
| 17090 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17091 | arraysize(data_writes)); |
| 17092 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17093 | |
| 17094 | TestCompletionCallback callback; |
| 17095 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17096 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17098 | |
| 17099 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17100 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17101 | } |
| 17102 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17103 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17104 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17105 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17106 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17107 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17108 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17109 | |
| 17110 | HttpRequestInfo request; |
| 17111 | request.method = "POST"; |
| 17112 | request.url = GURL("http://www.foo.com/"); |
| 17113 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17114 | request.traffic_annotation = |
| 17115 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17116 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17117 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17118 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17119 | // Send headers successfully, but get an error while sending the body. |
| 17120 | MockWrite data_writes[] = { |
| 17121 | MockWrite("POST / HTTP/1.1\r\n" |
| 17122 | "Host: www.foo.com\r\n" |
| 17123 | "Connection: keep-alive\r\n" |
| 17124 | "Content-Length: 3\r\n\r\n"), |
| 17125 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17126 | }; |
| 17127 | |
| 17128 | MockRead data_reads[] = { |
| 17129 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17130 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17131 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17132 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17133 | MockRead(SYNCHRONOUS, OK), |
| 17134 | }; |
| 17135 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17136 | arraysize(data_writes)); |
| 17137 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17138 | |
| 17139 | TestCompletionCallback callback; |
| 17140 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17141 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17142 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17143 | |
| 17144 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17145 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17146 | } |
| 17147 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17148 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17149 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17150 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17151 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17152 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17153 | |
| 17154 | HttpRequestInfo request; |
| 17155 | request.method = "POST"; |
| 17156 | request.url = GURL("http://www.foo.com/"); |
| 17157 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17158 | request.traffic_annotation = |
| 17159 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17160 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17161 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17162 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17163 | // Send headers successfully, but get an error while sending the body. |
| 17164 | MockWrite data_writes[] = { |
| 17165 | MockWrite("POST / HTTP/1.1\r\n" |
| 17166 | "Host: www.foo.com\r\n" |
| 17167 | "Connection: keep-alive\r\n" |
| 17168 | "Content-Length: 3\r\n\r\n"), |
| 17169 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17170 | }; |
| 17171 | |
| 17172 | MockRead data_reads[] = { |
| 17173 | MockRead("HTTP 0.9 rocks!"), |
| 17174 | MockRead(SYNCHRONOUS, OK), |
| 17175 | }; |
| 17176 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17177 | arraysize(data_writes)); |
| 17178 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17179 | |
| 17180 | TestCompletionCallback callback; |
| 17181 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17182 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17183 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17184 | |
| 17185 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17186 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17187 | } |
| 17188 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17189 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17190 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17191 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17192 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17193 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17194 | |
| 17195 | HttpRequestInfo request; |
| 17196 | request.method = "POST"; |
| 17197 | request.url = GURL("http://www.foo.com/"); |
| 17198 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17199 | request.traffic_annotation = |
| 17200 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17201 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17202 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17203 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17204 | // Send headers successfully, but get an error while sending the body. |
| 17205 | MockWrite data_writes[] = { |
| 17206 | MockWrite("POST / HTTP/1.1\r\n" |
| 17207 | "Host: www.foo.com\r\n" |
| 17208 | "Connection: keep-alive\r\n" |
| 17209 | "Content-Length: 3\r\n\r\n"), |
| 17210 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17211 | }; |
| 17212 | |
| 17213 | MockRead data_reads[] = { |
| 17214 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17215 | MockRead(SYNCHRONOUS, OK), |
| 17216 | }; |
| 17217 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17218 | arraysize(data_writes)); |
| 17219 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17220 | |
| 17221 | TestCompletionCallback callback; |
| 17222 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17223 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17224 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17225 | |
| 17226 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17227 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17228 | } |
| 17229 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17230 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17231 | |
| 17232 | namespace { |
| 17233 | |
| 17234 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17235 | headers->SetHeader("Connection", "Upgrade"); |
| 17236 | headers->SetHeader("Upgrade", "websocket"); |
| 17237 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17238 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17239 | } |
| 17240 | |
| 17241 | } // namespace |
| 17242 | |
| 17243 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17244 | std::string test_cases[] = {"ws://www.example.org/", |
| 17245 | "wss://www.example.org/"}; |
| 17246 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 17247 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17248 | HttpNetworkSessionPeer peer(session.get()); |
| 17249 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 17250 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
| 17251 | |
| 17252 | HttpRequestInfo request; |
| 17253 | request.method = "GET"; |
| 17254 | request.url = GURL(test_cases[i]); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17255 | request.traffic_annotation = |
| 17256 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17257 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17258 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17259 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17260 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17261 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 17262 | &websocket_stream_create_helper); |
| 17263 | |
| 17264 | TestCompletionCallback callback; |
| 17265 | EXPECT_EQ(ERR_IO_PENDING, |
| 17266 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 17267 | |
| 17268 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 17269 | fake_factory->last_stream_request(); |
| 17270 | ASSERT_TRUE(fake_request); |
| 17271 | EXPECT_EQ(&websocket_stream_create_helper, |
| 17272 | fake_request->websocket_stream_create_helper()); |
| 17273 | } |
| 17274 | } |
| 17275 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17276 | // Verify that proxy headers are not sent to the destination server when |
| 17277 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17278 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17279 | HttpRequestInfo request; |
| 17280 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17281 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17282 | request.traffic_annotation = |
| 17283 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17284 | AddWebSocketHeaders(&request.extra_headers); |
| 17285 | |
| 17286 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17287 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17288 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17289 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17290 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17291 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17292 | |
| 17293 | // Since a proxy is configured, try to establish a tunnel. |
| 17294 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17295 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17296 | "Host: www.example.org:443\r\n" |
| 17297 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17298 | |
| 17299 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17300 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17301 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17302 | "Host: www.example.org:443\r\n" |
| 17303 | "Proxy-Connection: keep-alive\r\n" |
| 17304 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17305 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17306 | MockWrite("GET / HTTP/1.1\r\n" |
| 17307 | "Host: www.example.org\r\n" |
| 17308 | "Connection: Upgrade\r\n" |
| 17309 | "Upgrade: websocket\r\n" |
| 17310 | "Origin: http://www.example.org\r\n" |
| 17311 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17312 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17313 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17314 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17315 | |
| 17316 | // The proxy responds to the connect with a 407, using a persistent |
| 17317 | // connection. |
| 17318 | MockRead data_reads[] = { |
| 17319 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17320 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17321 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17322 | "Content-Length: 0\r\n" |
| 17323 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17324 | |
| 17325 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17326 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17327 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17328 | "Upgrade: websocket\r\n" |
| 17329 | "Connection: Upgrade\r\n" |
| 17330 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17331 | |
| 17332 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17333 | arraysize(data_writes)); |
| 17334 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17335 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17336 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17337 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17338 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17339 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17340 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17341 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17342 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17343 | &websocket_stream_create_helper); |
| 17344 | |
| 17345 | { |
| 17346 | TestCompletionCallback callback; |
| 17347 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17348 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17349 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17350 | |
| 17351 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17352 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17353 | } |
| 17354 | |
| 17355 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17356 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17357 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17358 | EXPECT_EQ(407, response->headers->response_code()); |
| 17359 | |
| 17360 | { |
| 17361 | TestCompletionCallback callback; |
| 17362 | |
| 17363 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17364 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17365 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17366 | |
| 17367 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17368 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17369 | } |
| 17370 | |
| 17371 | response = trans->GetResponseInfo(); |
| 17372 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17373 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17374 | |
| 17375 | EXPECT_EQ(101, response->headers->response_code()); |
| 17376 | |
| 17377 | trans.reset(); |
| 17378 | session->CloseAllConnections(); |
| 17379 | } |
| 17380 | |
| 17381 | // Verify that proxy headers are not sent to the destination server when |
| 17382 | // establishing a tunnel for an insecure WebSocket connection. |
| 17383 | // This requires the authentication info to be injected into the auth cache |
| 17384 | // due to crbug.com/395064 |
| 17385 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17386 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17387 | HttpRequestInfo request; |
| 17388 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17389 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17390 | request.traffic_annotation = |
| 17391 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17392 | AddWebSocketHeaders(&request.extra_headers); |
| 17393 | |
| 17394 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17395 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17396 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17397 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17398 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17399 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17400 | |
| 17401 | MockWrite data_writes[] = { |
| 17402 | // Try to establish a tunnel for the WebSocket connection, with |
| 17403 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17404 | // they cannot and will not use the same TCP/IP connection as the |
| 17405 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17406 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17407 | "Host: www.example.org:80\r\n" |
| 17408 | "Proxy-Connection: keep-alive\r\n" |
| 17409 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17410 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17411 | MockWrite("GET / HTTP/1.1\r\n" |
| 17412 | "Host: www.example.org\r\n" |
| 17413 | "Connection: Upgrade\r\n" |
| 17414 | "Upgrade: websocket\r\n" |
| 17415 | "Origin: http://www.example.org\r\n" |
| 17416 | "Sec-WebSocket-Version: 13\r\n" |
| 17417 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17418 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17419 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17420 | |
| 17421 | MockRead data_reads[] = { |
| 17422 | // HTTP CONNECT with credentials. |
| 17423 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17424 | |
| 17425 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17426 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17427 | "Upgrade: websocket\r\n" |
| 17428 | "Connection: Upgrade\r\n" |
| 17429 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17430 | |
| 17431 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17432 | arraysize(data_writes)); |
| 17433 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17434 | |
| 17435 | session->http_auth_cache()->Add( |
| 17436 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17437 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17438 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17439 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17440 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17441 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17442 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17443 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17444 | &websocket_stream_create_helper); |
| 17445 | |
| 17446 | TestCompletionCallback callback; |
| 17447 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17448 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17449 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17450 | |
| 17451 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17452 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17453 | |
| 17454 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17455 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17456 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17457 | |
| 17458 | EXPECT_EQ(101, response->headers->response_code()); |
| 17459 | |
| 17460 | trans.reset(); |
| 17461 | session->CloseAllConnections(); |
| 17462 | } |
| 17463 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17464 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17465 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17466 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17467 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17468 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17469 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17470 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17471 | |
| 17472 | HttpRequestInfo request; |
| 17473 | request.method = "POST"; |
| 17474 | request.url = GURL("http://www.foo.com/"); |
| 17475 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17476 | request.traffic_annotation = |
| 17477 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17478 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17479 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17480 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17481 | MockWrite data_writes[] = { |
| 17482 | MockWrite("POST / HTTP/1.1\r\n" |
| 17483 | "Host: www.foo.com\r\n" |
| 17484 | "Connection: keep-alive\r\n" |
| 17485 | "Content-Length: 3\r\n\r\n"), |
| 17486 | MockWrite("foo"), |
| 17487 | }; |
| 17488 | |
| 17489 | MockRead data_reads[] = { |
| 17490 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17491 | MockRead(SYNCHRONOUS, OK), |
| 17492 | }; |
| 17493 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17494 | arraysize(data_writes)); |
| 17495 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17496 | |
| 17497 | TestCompletionCallback callback; |
| 17498 | |
| 17499 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17500 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17501 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17502 | |
| 17503 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17504 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17505 | |
| 17506 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17507 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17508 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17509 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17510 | } |
| 17511 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17512 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17513 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17514 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17515 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17516 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17517 | |
| 17518 | HttpRequestInfo request; |
| 17519 | request.method = "POST"; |
| 17520 | request.url = GURL("http://www.foo.com/"); |
| 17521 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17522 | request.traffic_annotation = |
| 17523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17524 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17525 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17526 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17527 | MockWrite data_writes[] = { |
| 17528 | MockWrite("POST / HTTP/1.1\r\n" |
| 17529 | "Host: www.foo.com\r\n" |
| 17530 | "Connection: keep-alive\r\n" |
| 17531 | "Content-Length: 3\r\n\r\n"), |
| 17532 | MockWrite("foo"), |
| 17533 | }; |
| 17534 | |
| 17535 | MockRead data_reads[] = { |
| 17536 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17537 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17538 | MockRead(SYNCHRONOUS, OK), |
| 17539 | }; |
| 17540 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17541 | arraysize(data_writes)); |
| 17542 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17543 | |
| 17544 | TestCompletionCallback callback; |
| 17545 | |
| 17546 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17547 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17548 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17549 | |
| 17550 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17551 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17552 | |
| 17553 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17554 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17555 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17556 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17557 | } |
| 17558 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17559 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17560 | ChunkedUploadDataStream upload_data_stream(0); |
| 17561 | |
| 17562 | HttpRequestInfo request; |
| 17563 | request.method = "POST"; |
| 17564 | request.url = GURL("http://www.foo.com/"); |
| 17565 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17566 | request.traffic_annotation = |
| 17567 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17568 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17569 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17570 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17571 | // Send headers successfully, but get an error while sending the body. |
| 17572 | MockWrite data_writes[] = { |
| 17573 | MockWrite("POST / HTTP/1.1\r\n" |
| 17574 | "Host: www.foo.com\r\n" |
| 17575 | "Connection: keep-alive\r\n" |
| 17576 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17577 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17578 | }; |
| 17579 | |
| 17580 | MockRead data_reads[] = { |
| 17581 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17582 | MockRead(SYNCHRONOUS, OK), |
| 17583 | }; |
| 17584 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17585 | arraysize(data_writes)); |
| 17586 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17587 | |
| 17588 | TestCompletionCallback callback; |
| 17589 | |
| 17590 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17591 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17592 | |
| 17593 | base::RunLoop().RunUntilIdle(); |
| 17594 | upload_data_stream.AppendData("f", 1, false); |
| 17595 | |
| 17596 | base::RunLoop().RunUntilIdle(); |
| 17597 | upload_data_stream.AppendData("oo", 2, true); |
| 17598 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17599 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17600 | |
| 17601 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17602 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17603 | |
| 17604 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17605 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17606 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17607 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17608 | } |
| 17609 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17610 | // Confirm that transactions whose throttle is created in (and stays in) |
| 17611 | // the unthrottled state are not blocked. |
| 17612 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 17613 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17614 | std::unique_ptr<HttpNetworkSession> session( |
| 17615 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17616 | |
| 17617 | // Send a simple request and make sure it goes through. |
| 17618 | HttpRequestInfo request; |
| 17619 | request.method = "GET"; |
| 17620 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17621 | request.traffic_annotation = |
| 17622 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17623 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17624 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17625 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17626 | |
| 17627 | MockWrite data_writes[] = { |
| 17628 | MockWrite("GET / HTTP/1.1\r\n" |
| 17629 | "Host: www.example.org\r\n" |
| 17630 | "Connection: keep-alive\r\n\r\n"), |
| 17631 | }; |
| 17632 | MockRead data_reads[] = { |
| 17633 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17634 | MockRead(SYNCHRONOUS, OK), |
| 17635 | }; |
| 17636 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17637 | arraysize(data_writes)); |
| 17638 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17639 | |
| 17640 | TestCompletionCallback callback; |
| 17641 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17642 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17643 | } |
| 17644 | |
| 17645 | // Confirm requests can be blocked by a throttler, and are resumed |
| 17646 | // when the throttle is unblocked. |
| 17647 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 17648 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17649 | std::unique_ptr<HttpNetworkSession> session( |
| 17650 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17651 | |
| 17652 | // Send a simple request and make sure it goes through. |
| 17653 | HttpRequestInfo request; |
| 17654 | request.method = "GET"; |
| 17655 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17656 | request.traffic_annotation = |
| 17657 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17658 | |
| 17659 | MockWrite data_writes[] = { |
| 17660 | MockWrite("GET / HTTP/1.1\r\n" |
| 17661 | "Host: www.example.org\r\n" |
| 17662 | "Connection: keep-alive\r\n\r\n"), |
| 17663 | }; |
| 17664 | MockRead data_reads[] = { |
| 17665 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17666 | MockRead(SYNCHRONOUS, OK), |
| 17667 | }; |
| 17668 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17669 | arraysize(data_writes)); |
| 17670 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17671 | |
| 17672 | // Start a request that will be throttled at start; confirm it |
| 17673 | // doesn't complete. |
| 17674 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17675 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17676 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17677 | |
| 17678 | TestCompletionCallback callback; |
| 17679 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17680 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17681 | |
| 17682 | base::RunLoop().RunUntilIdle(); |
| 17683 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17684 | EXPECT_FALSE(callback.have_result()); |
| 17685 | |
| 17686 | // Confirm the request goes on to complete when unthrottled. |
| 17687 | throttler->UnthrottleAllRequests(); |
| 17688 | base::RunLoop().RunUntilIdle(); |
| 17689 | ASSERT_TRUE(callback.have_result()); |
| 17690 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17691 | } |
| 17692 | |
| 17693 | // Destroy a request while it's throttled. |
| 17694 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 17695 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17696 | std::unique_ptr<HttpNetworkSession> session( |
| 17697 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17698 | |
| 17699 | // Send a simple request and make sure it goes through. |
| 17700 | HttpRequestInfo request; |
| 17701 | request.method = "GET"; |
| 17702 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17703 | request.traffic_annotation = |
| 17704 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17705 | |
| 17706 | MockWrite data_writes[] = { |
| 17707 | MockWrite("GET / HTTP/1.1\r\n" |
| 17708 | "Host: www.example.org\r\n" |
| 17709 | "Connection: keep-alive\r\n\r\n"), |
| 17710 | }; |
| 17711 | MockRead data_reads[] = { |
| 17712 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17713 | MockRead(SYNCHRONOUS, OK), |
| 17714 | }; |
| 17715 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17716 | arraysize(data_writes)); |
| 17717 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17718 | |
| 17719 | // Start a request that will be throttled at start; confirm it |
| 17720 | // doesn't complete. |
| 17721 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17722 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17723 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17724 | |
| 17725 | TestCompletionCallback callback; |
| 17726 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17727 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17728 | |
| 17729 | base::RunLoop().RunUntilIdle(); |
| 17730 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17731 | EXPECT_FALSE(callback.have_result()); |
| 17732 | |
| 17733 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 17734 | trans.reset(); |
| 17735 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 17736 | } |
| 17737 | |
| 17738 | // Confirm the throttler receives SetPriority calls. |
| 17739 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 17740 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17741 | std::unique_ptr<HttpNetworkSession> session( |
| 17742 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17743 | |
| 17744 | // Send a simple request and make sure it goes through. |
| 17745 | HttpRequestInfo request; |
| 17746 | request.method = "GET"; |
| 17747 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17748 | request.traffic_annotation = |
| 17749 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17750 | |
| 17751 | MockWrite data_writes[] = { |
| 17752 | MockWrite("GET / HTTP/1.1\r\n" |
| 17753 | "Host: www.example.org\r\n" |
| 17754 | "Connection: keep-alive\r\n\r\n"), |
| 17755 | }; |
| 17756 | MockRead data_reads[] = { |
| 17757 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17758 | MockRead(SYNCHRONOUS, OK), |
| 17759 | }; |
| 17760 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17761 | arraysize(data_writes)); |
| 17762 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17763 | |
| 17764 | throttler->set_throttle_new_requests(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17765 | auto trans = std::make_unique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17766 | // Start the transaction to associate a throttle with it. |
| 17767 | TestCompletionCallback callback; |
| 17768 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17769 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17770 | |
| 17771 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 17772 | trans->SetPriority(LOW); |
| 17773 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 17774 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 17775 | |
| 17776 | throttler->UnthrottleAllRequests(); |
| 17777 | base::RunLoop().RunUntilIdle(); |
| 17778 | ASSERT_TRUE(callback.have_result()); |
| 17779 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17780 | } |
| 17781 | |
| 17782 | // Confirm that unthrottling from a SetPriority call by the |
| 17783 | // throttler works properly. |
| 17784 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 17785 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17786 | std::unique_ptr<HttpNetworkSession> session( |
| 17787 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17788 | |
| 17789 | // Send a simple request and make sure it goes through. |
| 17790 | HttpRequestInfo request; |
| 17791 | request.method = "GET"; |
| 17792 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17793 | request.traffic_annotation = |
| 17794 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17795 | |
| 17796 | MockWrite data_writes[] = { |
| 17797 | MockWrite("GET / HTTP/1.1\r\n" |
| 17798 | "Host: www.example.org\r\n" |
| 17799 | "Connection: keep-alive\r\n\r\n"), |
| 17800 | }; |
| 17801 | MockRead data_reads[] = { |
| 17802 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17803 | MockRead(SYNCHRONOUS, OK), |
| 17804 | }; |
| 17805 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17806 | arraysize(data_writes)); |
| 17807 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17808 | |
| 17809 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17810 | data_writes, arraysize(data_writes)); |
| 17811 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17812 | |
| 17813 | // Start a request that will be throttled at start; confirm it |
| 17814 | // doesn't complete. |
| 17815 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17816 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17817 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17818 | |
| 17819 | TestCompletionCallback callback; |
| 17820 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17821 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17822 | |
| 17823 | base::RunLoop().RunUntilIdle(); |
| 17824 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17825 | EXPECT_FALSE(callback.have_result()); |
| 17826 | |
| 17827 | // Create a new request, call SetPriority on it to unthrottle, |
| 17828 | // and make sure that allows the original request to complete. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17829 | auto trans1 = std::make_unique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17830 | throttler->set_priority_change_closure( |
| 17831 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 17832 | base::Unretained(throttler))); |
| 17833 | |
| 17834 | // Start the transaction to associate a throttle with it. |
| 17835 | TestCompletionCallback callback1; |
| 17836 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 17837 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17838 | |
| 17839 | trans1->SetPriority(IDLE); |
| 17840 | |
| 17841 | base::RunLoop().RunUntilIdle(); |
| 17842 | ASSERT_TRUE(callback.have_result()); |
| 17843 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17844 | ASSERT_TRUE(callback1.have_result()); |
| 17845 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 17846 | } |
| 17847 | |
| 17848 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17849 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17850 | |
| 17851 | // Confirm that destroying a transaction from a SetPriority call by the |
| 17852 | // throttler works properly. |
| 17853 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 17854 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17855 | std::unique_ptr<HttpNetworkSession> session( |
| 17856 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17857 | |
| 17858 | // Send a simple request and make sure it goes through. |
| 17859 | HttpRequestInfo request; |
| 17860 | request.method = "GET"; |
| 17861 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17862 | request.traffic_annotation = |
| 17863 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17864 | |
| 17865 | MockWrite data_writes[] = { |
| 17866 | MockWrite("GET / HTTP/1.1\r\n" |
| 17867 | "Host: www.example.org\r\n" |
| 17868 | "Connection: keep-alive\r\n\r\n"), |
| 17869 | }; |
| 17870 | MockRead data_reads[] = { |
| 17871 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17872 | MockRead(SYNCHRONOUS, OK), |
| 17873 | }; |
| 17874 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17875 | arraysize(data_writes)); |
| 17876 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17877 | |
| 17878 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17879 | data_writes, arraysize(data_writes)); |
| 17880 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17881 | |
| 17882 | // Start a request that will be throttled at start; confirm it |
| 17883 | // doesn't complete. |
| 17884 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17885 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17886 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17887 | |
| 17888 | TestCompletionCallback callback; |
| 17889 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17890 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17891 | |
| 17892 | base::RunLoop().RunUntilIdle(); |
| 17893 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17894 | EXPECT_FALSE(callback.have_result()); |
| 17895 | |
| 17896 | // Arrange for the set priority call on the above transaction to delete |
| 17897 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17898 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17899 | throttler->set_priority_change_closure( |
| 17900 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 17901 | |
| 17902 | // Call it and check results (partially a "doesn't crash" test). |
| 17903 | trans_ptr->SetPriority(IDLE); |
| 17904 | trans_ptr = nullptr; // No longer a valid pointer. |
| 17905 | |
| 17906 | base::RunLoop().RunUntilIdle(); |
| 17907 | ASSERT_FALSE(callback.have_result()); |
| 17908 | } |
| 17909 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17910 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17911 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17912 | const std::string https_url = "https://www.example.com"; |
| 17913 | HttpRequestInfo request; |
| 17914 | request.url = GURL(https_url); |
| 17915 | request.method = "GET"; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17916 | request.traffic_annotation = |
| 17917 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17918 | |
| 17919 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17920 | ssl.ssl_info.token_binding_negotiated = true; |
| 17921 | ssl.ssl_info.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17922 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17923 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17924 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17925 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17926 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 17927 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17928 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 17929 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 17930 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17931 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17932 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17933 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17934 | |
| 17935 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17936 | TestCompletionCallback callback; |
| 17937 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17938 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17939 | |
| 17940 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17941 | |
| 17942 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17943 | HttpRequestHeaders headers; |
| 17944 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17945 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17946 | } |
| 17947 | #endif // !defined(OS_IOS) |
| 17948 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17949 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17950 | const std::string& accept_encoding, |
| 17951 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17952 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17953 | bool should_match) { |
| 17954 | HttpRequestInfo request; |
| 17955 | request.method = "GET"; |
| 17956 | request.url = GURL("http://www.foo.com/"); |
| 17957 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17958 | accept_encoding); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17959 | request.traffic_annotation = |
| 17960 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17961 | |
| 17962 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17963 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17964 | // Send headers successfully, but get an error while sending the body. |
| 17965 | MockWrite data_writes[] = { |
| 17966 | MockWrite("GET / HTTP/1.1\r\n" |
| 17967 | "Host: www.foo.com\r\n" |
| 17968 | "Connection: keep-alive\r\n" |
| 17969 | "Accept-Encoding: "), |
| 17970 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17971 | }; |
| 17972 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17973 | std::string response_code = "200 OK"; |
| 17974 | std::string extra; |
| 17975 | if (!location.empty()) { |
| 17976 | response_code = "301 Redirect\r\nLocation: "; |
| 17977 | response_code.append(location); |
| 17978 | } |
| 17979 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17980 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17981 | MockRead("HTTP/1.0 "), |
| 17982 | MockRead(response_code.data()), |
| 17983 | MockRead("\r\nContent-Encoding: "), |
| 17984 | MockRead(content_encoding.data()), |
| 17985 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17986 | MockRead(SYNCHRONOUS, OK), |
| 17987 | }; |
| 17988 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17989 | arraysize(data_writes)); |
| 17990 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17991 | |
| 17992 | TestCompletionCallback callback; |
| 17993 | |
| 17994 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17995 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17996 | |
| 17997 | rv = callback.WaitForResult(); |
| 17998 | if (should_match) { |
| 17999 | EXPECT_THAT(rv, IsOk()); |
| 18000 | } else { |
| 18001 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18002 | } |
| 18003 | } |
| 18004 | |
| 18005 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18006 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18007 | } |
| 18008 | |
| 18009 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18010 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18011 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18012 | } |
| 18013 | |
| 18014 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18015 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18016 | "", false); |
| 18017 | } |
| 18018 | |
| 18019 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18020 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18021 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18022 | } |
| 18023 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18024 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18025 | ProxyConfig proxy_config; |
| 18026 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18027 | proxy_config.set_pac_mandatory(true); |
| 18028 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18029 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18030 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18031 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18032 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18033 | |
| 18034 | HttpRequestInfo request; |
| 18035 | request.method = "GET"; |
| 18036 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18037 | request.traffic_annotation = |
| 18038 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18039 | |
| 18040 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18041 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18042 | |
| 18043 | TestCompletionCallback callback; |
| 18044 | |
| 18045 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18047 | EXPECT_THAT(callback.WaitForResult(), |
| 18048 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18049 | } |
| 18050 | |
| 18051 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18052 | ProxyConfig proxy_config; |
| 18053 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18054 | proxy_config.set_pac_mandatory(true); |
| 18055 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18056 | new MockAsyncProxyResolverFactory(false); |
| 18057 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18058 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18059 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18060 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18061 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18062 | HttpRequestInfo request; |
| 18063 | request.method = "GET"; |
| 18064 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18065 | request.traffic_annotation = |
| 18066 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18067 | |
| 18068 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18069 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18070 | |
| 18071 | TestCompletionCallback callback; |
| 18072 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18074 | |
| 18075 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18076 | ERR_FAILED, &resolver); |
| 18077 | EXPECT_THAT(callback.WaitForResult(), |
| 18078 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18079 | } |
| 18080 | |
| 18081 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18082 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18083 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18084 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18085 | session_deps_.enable_quic = false; |
| 18086 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18087 | |
| 18088 | HttpRequestInfo request; |
| 18089 | request.method = "GET"; |
| 18090 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18091 | request.traffic_annotation = |
| 18092 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18093 | |
| 18094 | TestCompletionCallback callback; |
| 18095 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18096 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18098 | |
| 18099 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18100 | } |
| 18101 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 18102 | } // namespace net |