[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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | b5e433e | 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 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2693 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2694 | HttpRequestInfo request; |
| 2695 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2696 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2697 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2698 | request.traffic_annotation = |
| 2699 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2700 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2701 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2702 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2703 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2704 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2705 | MockWrite( |
| 2706 | "GET / HTTP/1.1\r\n" |
| 2707 | "Host: www.example.org\r\n" |
| 2708 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2709 | }; |
| 2710 | |
| 2711 | MockRead data_reads[] = { |
| 2712 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2713 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2714 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2715 | // Large content-length -- won't matter, as connection will be reset. |
| 2716 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2717 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2718 | }; |
| 2719 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2720 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2721 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2722 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2723 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2724 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2725 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2726 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2727 | |
| 2728 | rv = callback.WaitForResult(); |
| 2729 | EXPECT_EQ(0, rv); |
| 2730 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2731 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2732 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2733 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2734 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2735 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2736 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2737 | ASSERT_TRUE(response); |
| 2738 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2739 | } |
| 2740 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2741 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2742 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2743 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2744 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2745 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2746 | // reused. See http://crbug.com/544255. |
| 2747 | for (int i = 0; i < 2; ++i) { |
| 2748 | HttpRequestInfo request; |
| 2749 | request.method = "GET"; |
| 2750 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2751 | request.traffic_annotation = |
| 2752 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2753 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2754 | TestNetLog log; |
| 2755 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2756 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2757 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2758 | MockWrite data_writes[] = { |
| 2759 | MockWrite(ASYNC, 0, |
| 2760 | "GET / HTTP/1.1\r\n" |
| 2761 | "Host: www.example.org\r\n" |
| 2762 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2763 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2764 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2765 | // be issuing -- the final header line contains the credentials. |
| 2766 | MockWrite(ASYNC, 6, |
| 2767 | "GET / HTTP/1.1\r\n" |
| 2768 | "Host: www.example.org\r\n" |
| 2769 | "Connection: keep-alive\r\n" |
| 2770 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2771 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2772 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2773 | MockRead data_reads[] = { |
| 2774 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2775 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2776 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2777 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2778 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2779 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2780 | // Lastly, the server responds with the actual content. |
| 2781 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2782 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2783 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2784 | MockRead(ASYNC, 10, "Hello"), |
| 2785 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2786 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2787 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2788 | arraysize(data_writes)); |
| 2789 | data.set_busy_before_sync_reads(true); |
| 2790 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2791 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2792 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2793 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2794 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2795 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2796 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2797 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2798 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2799 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2800 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2801 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2802 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2803 | ASSERT_TRUE(response); |
| 2804 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2805 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2806 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2807 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2808 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2809 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2810 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2811 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2812 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2813 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2814 | TestLoadTimingReused(load_timing_info2); |
| 2815 | // The load timing after restart should have the same socket ID, and times |
| 2816 | // those of the first load timing. |
| 2817 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2818 | load_timing_info2.send_start); |
| 2819 | 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] | 2820 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2821 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2822 | ASSERT_TRUE(response); |
| 2823 | EXPECT_FALSE(response->auth_challenge); |
| 2824 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2825 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2826 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2827 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2828 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2829 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2830 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2831 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2832 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2833 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2837 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2838 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2839 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2840 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2841 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2842 | request.traffic_annotation = |
| 2843 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2844 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2845 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2846 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2847 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2848 | MockWrite("GET / HTTP/1.1\r\n" |
| 2849 | "Host: www.example.org\r\n" |
| 2850 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2852 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2853 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2854 | MockWrite("GET / HTTP/1.1\r\n" |
| 2855 | "Host: www.example.org\r\n" |
| 2856 | "Connection: keep-alive\r\n" |
| 2857 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2858 | }; |
| 2859 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2860 | MockRead data_reads1[] = { |
| 2861 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2862 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2863 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2864 | |
| 2865 | // Lastly, the server responds with the actual content. |
| 2866 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2867 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2868 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2869 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2870 | }; |
| 2871 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2872 | // An incorrect reconnect would cause this to be read. |
| 2873 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2874 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2875 | }; |
| 2876 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2877 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2878 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2879 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2880 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2881 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2882 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2884 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2885 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2886 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2887 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2888 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2889 | |
| 2890 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2891 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2892 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2893 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2894 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2895 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2897 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2898 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2899 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2900 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2901 | |
| 2902 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2903 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2904 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2905 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2906 | ASSERT_TRUE(response); |
| 2907 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2908 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2912 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2913 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2914 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2915 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2916 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2917 | request.traffic_annotation = |
| 2918 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2919 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2920 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2921 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2922 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2923 | MockWrite("GET / HTTP/1.1\r\n" |
| 2924 | "Host: www.example.org\r\n" |
| 2925 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2926 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2927 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2928 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2929 | MockWrite("GET / HTTP/1.1\r\n" |
| 2930 | "Host: www.example.org\r\n" |
| 2931 | "Connection: keep-alive\r\n" |
| 2932 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2933 | }; |
| 2934 | |
| 2935 | // Respond with 5 kb of response body. |
| 2936 | std::string large_body_string("Unauthorized"); |
| 2937 | large_body_string.append(5 * 1024, ' '); |
| 2938 | large_body_string.append("\r\n"); |
| 2939 | |
| 2940 | MockRead data_reads1[] = { |
| 2941 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2942 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2943 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2944 | // 5134 = 12 + 5 * 1024 + 2 |
| 2945 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2946 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2947 | |
| 2948 | // Lastly, the server responds with the actual content. |
| 2949 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2950 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2951 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2952 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2953 | }; |
| 2954 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2955 | // An incorrect reconnect would cause this to be read. |
| 2956 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2957 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2958 | }; |
| 2959 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2960 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2961 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2962 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2963 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2964 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2965 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2966 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2967 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2968 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2969 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2970 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
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 = callback1.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 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2977 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2978 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2980 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2981 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2982 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2984 | |
| 2985 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2986 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2987 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2988 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2989 | ASSERT_TRUE(response); |
| 2990 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2991 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2992 | } |
| 2993 | |
| 2994 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2995 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2996 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2997 | HttpRequestInfo request; |
| 2998 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2999 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3000 | request.traffic_annotation = |
| 3001 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3002 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3003 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3004 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3005 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3006 | MockWrite( |
| 3007 | "GET / HTTP/1.1\r\n" |
| 3008 | "Host: www.example.org\r\n" |
| 3009 | "Connection: keep-alive\r\n\r\n"), |
| 3010 | // This simulates the seemingly successful write to a closed connection |
| 3011 | // if the bug is not fixed. |
| 3012 | MockWrite( |
| 3013 | "GET / HTTP/1.1\r\n" |
| 3014 | "Host: www.example.org\r\n" |
| 3015 | "Connection: keep-alive\r\n" |
| 3016 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3017 | }; |
| 3018 | |
| 3019 | MockRead data_reads1[] = { |
| 3020 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3021 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3022 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3023 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3024 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3025 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3026 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3027 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3028 | }; |
| 3029 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3030 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3031 | // be issuing -- the final header line contains the credentials. |
| 3032 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3033 | MockWrite( |
| 3034 | "GET / HTTP/1.1\r\n" |
| 3035 | "Host: www.example.org\r\n" |
| 3036 | "Connection: keep-alive\r\n" |
| 3037 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3038 | }; |
| 3039 | |
| 3040 | // Lastly, the server responds with the actual content. |
| 3041 | MockRead data_reads2[] = { |
| 3042 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3043 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3044 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3045 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3046 | }; |
| 3047 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3048 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3049 | data_writes1, arraysize(data_writes1)); |
| 3050 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3051 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3052 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3053 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3055 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3056 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3057 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3058 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3059 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3060 | |
| 3061 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3062 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3063 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3064 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3065 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3066 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3067 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3068 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3069 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3070 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3071 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3072 | |
| 3073 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3074 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3075 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3076 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3077 | ASSERT_TRUE(response); |
| 3078 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3079 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3080 | } |
| 3081 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3082 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3083 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3084 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3085 | HttpRequestInfo request; |
| 3086 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3087 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3088 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3089 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3090 | request.traffic_annotation = |
| 3091 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3092 | |
| 3093 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3094 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3095 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3096 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3097 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3098 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3099 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3100 | |
| 3101 | // Since we have proxy, should try to establish tunnel. |
| 3102 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3103 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3104 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3105 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3106 | }; |
| 3107 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3108 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3109 | // connection. |
| 3110 | MockRead data_reads1[] = { |
| 3111 | // No credentials. |
| 3112 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3113 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3114 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3115 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3116 | // Since the first connection couldn't be reused, need to establish another |
| 3117 | // once given credentials. |
| 3118 | MockWrite data_writes2[] = { |
| 3119 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3120 | // be issuing -- the final header line contains the credentials. |
| 3121 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3122 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3123 | "Proxy-Connection: keep-alive\r\n" |
| 3124 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3125 | |
| 3126 | MockWrite("GET / HTTP/1.1\r\n" |
| 3127 | "Host: www.example.org\r\n" |
| 3128 | "Connection: keep-alive\r\n\r\n"), |
| 3129 | }; |
| 3130 | |
| 3131 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3132 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3133 | |
| 3134 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3135 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3136 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3137 | MockRead(SYNCHRONOUS, "hello"), |
| 3138 | }; |
| 3139 | |
| 3140 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3141 | data_writes1, arraysize(data_writes1)); |
| 3142 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3143 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3144 | data_writes2, arraysize(data_writes2)); |
| 3145 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3146 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3148 | |
| 3149 | TestCompletionCallback callback1; |
| 3150 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3151 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3152 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3153 | |
| 3154 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3155 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3156 | |
| 3157 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3158 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3159 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3160 | log.GetEntries(&entries); |
| 3161 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3162 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3163 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3164 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3165 | entries, pos, |
| 3166 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3167 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3168 | |
| 3169 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3170 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3171 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3172 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3173 | EXPECT_EQ(407, response->headers->response_code()); |
| 3174 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3175 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3176 | |
| 3177 | LoadTimingInfo load_timing_info; |
| 3178 | // CONNECT requests and responses are handled at the connect job level, so |
| 3179 | // the transaction does not yet have a connection. |
| 3180 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3181 | |
| 3182 | TestCompletionCallback callback2; |
| 3183 | |
| 3184 | rv = |
| 3185 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3186 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3187 | |
| 3188 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3189 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3190 | |
| 3191 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3192 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3193 | |
| 3194 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3195 | EXPECT_EQ(200, response->headers->response_code()); |
| 3196 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3197 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3198 | |
| 3199 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3200 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3201 | |
| 3202 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3203 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3204 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3205 | |
| 3206 | trans.reset(); |
| 3207 | session->CloseAllConnections(); |
| 3208 | } |
| 3209 | |
| 3210 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3211 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3212 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3213 | HttpRequestInfo request; |
| 3214 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3215 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3216 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3217 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3218 | request.traffic_annotation = |
| 3219 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3220 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3221 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3222 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3223 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3224 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3225 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3226 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3227 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3228 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3229 | // Since we have proxy, should try to establish tunnel. |
| 3230 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3231 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3232 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3233 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3234 | }; |
| 3235 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3236 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3237 | // connection. |
| 3238 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3239 | // No credentials. |
| 3240 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3241 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3242 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3243 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3244 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3245 | MockWrite data_writes2[] = { |
| 3246 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3247 | // be issuing -- the final header line contains the credentials. |
| 3248 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3249 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3250 | "Proxy-Connection: keep-alive\r\n" |
| 3251 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3252 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3253 | MockWrite("GET / HTTP/1.1\r\n" |
| 3254 | "Host: www.example.org\r\n" |
| 3255 | "Connection: keep-alive\r\n\r\n"), |
| 3256 | }; |
| 3257 | |
| 3258 | MockRead data_reads2[] = { |
| 3259 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3260 | |
| 3261 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3262 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3263 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3264 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3265 | }; |
| 3266 | |
| 3267 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3268 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3269 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3270 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3271 | data_writes2, arraysize(data_writes2)); |
| 3272 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3273 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3274 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3275 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3276 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3277 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3278 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3279 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3280 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3281 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3283 | |
| 3284 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3285 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3286 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3287 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3288 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3289 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3290 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3291 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3292 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3293 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3294 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3295 | |
| 3296 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3297 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3298 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3299 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3300 | EXPECT_EQ(407, response->headers->response_code()); |
| 3301 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3302 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3303 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3304 | LoadTimingInfo load_timing_info; |
| 3305 | // CONNECT requests and responses are handled at the connect job level, so |
| 3306 | // the transaction does not yet have a connection. |
| 3307 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3308 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3309 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3310 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3311 | rv = trans->RestartWithAuth( |
| 3312 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3313 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3314 | |
| 3315 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3316 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3317 | |
| 3318 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3319 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3320 | |
| 3321 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3322 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3323 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3324 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3325 | |
| 3326 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3327 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3328 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3329 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3330 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3331 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3332 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3333 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3334 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3335 | } |
| 3336 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3337 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3338 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3339 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3340 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3341 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3342 | // reused. See http://crbug.com/544255. |
| 3343 | for (int i = 0; i < 2; ++i) { |
| 3344 | HttpRequestInfo request; |
| 3345 | request.method = "GET"; |
| 3346 | request.url = GURL("https://www.example.org/"); |
| 3347 | // Ensure that proxy authentication is attempted even |
| 3348 | // when the no authentication data flag is set. |
| 3349 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3350 | request.traffic_annotation = |
| 3351 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3352 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3353 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3354 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3355 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3356 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3357 | BoundTestNetLog log; |
| 3358 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3359 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3360 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3361 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3362 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3363 | // Since we have proxy, should try to establish tunnel. |
| 3364 | MockWrite data_writes1[] = { |
| 3365 | MockWrite(ASYNC, 0, |
| 3366 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3367 | "Host: www.example.org:443\r\n" |
| 3368 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3369 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3370 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3371 | // be issuing -- the final header line contains the credentials. |
| 3372 | MockWrite(ASYNC, 3, |
| 3373 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3374 | "Host: www.example.org:443\r\n" |
| 3375 | "Proxy-Connection: keep-alive\r\n" |
| 3376 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3377 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3378 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3379 | // The proxy responds to the connect with a 407, using a persistent |
| 3380 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3381 | MockRead data_reads1[] = { |
| 3382 | // No credentials. |
| 3383 | MockRead(ASYNC, 1, |
| 3384 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3385 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3386 | "Proxy-Connection: keep-alive\r\n" |
| 3387 | "Content-Length: 10\r\n\r\n"), |
| 3388 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3389 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3390 | // Wrong credentials (wrong password). |
| 3391 | MockRead(ASYNC, 4, |
| 3392 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3393 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3394 | "Proxy-Connection: keep-alive\r\n" |
| 3395 | "Content-Length: 10\r\n\r\n"), |
| 3396 | // No response body because the test stops reading here. |
| 3397 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3398 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3399 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3400 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3401 | arraysize(data_writes1)); |
| 3402 | data1.set_busy_before_sync_reads(true); |
| 3403 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3404 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3405 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3407 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3408 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3409 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3410 | TestNetLogEntry::List entries; |
| 3411 | log.GetEntries(&entries); |
| 3412 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3413 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3414 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3415 | ExpectLogContainsSomewhere( |
| 3416 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3417 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3418 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3419 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3420 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3421 | ASSERT_TRUE(response); |
| 3422 | ASSERT_TRUE(response->headers); |
| 3423 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3424 | EXPECT_EQ(407, response->headers->response_code()); |
| 3425 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3426 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3427 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3428 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3429 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3430 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3431 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3432 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3433 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3434 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3435 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3436 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3437 | ASSERT_TRUE(response); |
| 3438 | ASSERT_TRUE(response->headers); |
| 3439 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3440 | EXPECT_EQ(407, response->headers->response_code()); |
| 3441 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3442 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3443 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3444 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3445 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3446 | // out of scope. |
| 3447 | session->CloseAllConnections(); |
| 3448 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3449 | } |
| 3450 | |
| 3451 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3452 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3453 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3454 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3455 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3456 | // reused. See http://crbug.com/544255. |
| 3457 | for (int i = 0; i < 2; ++i) { |
| 3458 | HttpRequestInfo request; |
| 3459 | request.method = "GET"; |
| 3460 | request.url = GURL("https://www.example.org/"); |
| 3461 | // Ensure that proxy authentication is attempted even |
| 3462 | // when the no authentication data flag is set. |
| 3463 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3464 | request.traffic_annotation = |
| 3465 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3466 | |
| 3467 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3468 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3469 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3470 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3471 | BoundTestNetLog log; |
| 3472 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3473 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3475 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3476 | |
| 3477 | // Since we have proxy, should try to establish tunnel. |
| 3478 | MockWrite data_writes1[] = { |
| 3479 | MockWrite(ASYNC, 0, |
| 3480 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3481 | "Host: www.example.org:443\r\n" |
| 3482 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3483 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3484 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3485 | // be issuing -- the final header line contains the credentials. |
| 3486 | MockWrite(ASYNC, 3, |
| 3487 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3488 | "Host: www.example.org:443\r\n" |
| 3489 | "Proxy-Connection: keep-alive\r\n" |
| 3490 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3491 | }; |
| 3492 | |
| 3493 | // The proxy responds to the connect with a 407, using a persistent |
| 3494 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3495 | MockRead data_reads1[] = { |
| 3496 | // No credentials. |
| 3497 | MockRead(ASYNC, 1, |
| 3498 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3499 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3500 | "Content-Length: 10\r\n\r\n"), |
| 3501 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3502 | |
| 3503 | // Wrong credentials (wrong password). |
| 3504 | MockRead(ASYNC, 4, |
| 3505 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3506 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3507 | "Content-Length: 10\r\n\r\n"), |
| 3508 | // No response body because the test stops reading here. |
| 3509 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3510 | }; |
| 3511 | |
| 3512 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3513 | arraysize(data_writes1)); |
| 3514 | data1.set_busy_before_sync_reads(true); |
| 3515 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3516 | |
| 3517 | TestCompletionCallback callback1; |
| 3518 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3519 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3520 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3521 | |
| 3522 | TestNetLogEntry::List entries; |
| 3523 | log.GetEntries(&entries); |
| 3524 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3525 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3526 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3527 | ExpectLogContainsSomewhere( |
| 3528 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3529 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3530 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3531 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3532 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3533 | ASSERT_TRUE(response); |
| 3534 | ASSERT_TRUE(response->headers); |
| 3535 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3536 | EXPECT_EQ(407, response->headers->response_code()); |
| 3537 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3538 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3539 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3540 | |
| 3541 | TestCompletionCallback callback2; |
| 3542 | |
| 3543 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3544 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3545 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3546 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3547 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3548 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3549 | ASSERT_TRUE(response); |
| 3550 | ASSERT_TRUE(response->headers); |
| 3551 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3552 | EXPECT_EQ(407, response->headers->response_code()); |
| 3553 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3554 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3555 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3556 | |
| 3557 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3558 | // out of scope. |
| 3559 | session->CloseAllConnections(); |
| 3560 | } |
| 3561 | } |
| 3562 | |
| 3563 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3564 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3565 | // the case the server sends extra data on the original socket, so it can't be |
| 3566 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3567 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3568 | HttpRequestInfo request; |
| 3569 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3570 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3571 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3572 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3573 | request.traffic_annotation = |
| 3574 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3575 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3576 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3577 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3578 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3579 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3580 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3581 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3582 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3583 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3584 | // Since we have proxy, should try to establish tunnel. |
| 3585 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3586 | MockWrite(ASYNC, 0, |
| 3587 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3588 | "Host: www.example.org:443\r\n" |
| 3589 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3590 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3591 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3592 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3593 | // extra data, so the socket cannot be reused. |
| 3594 | MockRead data_reads1[] = { |
| 3595 | // No credentials. |
| 3596 | MockRead(ASYNC, 1, |
| 3597 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3598 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3599 | "Content-Length: 10\r\n\r\n"), |
| 3600 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3601 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3602 | }; |
| 3603 | |
| 3604 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3605 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3606 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3607 | MockWrite(ASYNC, 0, |
| 3608 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3609 | "Host: www.example.org:443\r\n" |
| 3610 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3611 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3612 | |
| 3613 | MockWrite(ASYNC, 2, |
| 3614 | "GET / HTTP/1.1\r\n" |
| 3615 | "Host: www.example.org\r\n" |
| 3616 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3617 | }; |
| 3618 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3619 | MockRead data_reads2[] = { |
| 3620 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3621 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3622 | MockRead(ASYNC, 3, |
| 3623 | "HTTP/1.1 200 OK\r\n" |
| 3624 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3625 | "Content-Length: 5\r\n\r\n"), |
| 3626 | // No response body because the test stops reading here. |
| 3627 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3628 | }; |
| 3629 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3630 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3631 | arraysize(data_writes1)); |
| 3632 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3633 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3634 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3635 | arraysize(data_writes2)); |
| 3636 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3637 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3638 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3639 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3640 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3641 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3642 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3643 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3644 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3645 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3646 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3647 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3648 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3649 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3650 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3651 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3652 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3653 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3654 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3655 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3656 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3657 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3658 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3659 | ASSERT_TRUE(response); |
| 3660 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3661 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3662 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3663 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3664 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3665 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3666 | LoadTimingInfo load_timing_info; |
| 3667 | // CONNECT requests and responses are handled at the connect job level, so |
| 3668 | // the transaction does not yet have a connection. |
| 3669 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3670 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3671 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3672 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3673 | rv = |
| 3674 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3675 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3676 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3677 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3678 | EXPECT_EQ(200, response->headers->response_code()); |
| 3679 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3680 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3681 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3682 | // The password prompt info should not be set. |
| 3683 | EXPECT_FALSE(response->auth_challenge); |
| 3684 | |
| 3685 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3686 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3687 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3688 | |
| 3689 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3690 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3691 | } |
| 3692 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3693 | // Test the case a proxy closes a socket while the challenge body is being |
| 3694 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3695 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3696 | HttpRequestInfo request; |
| 3697 | request.method = "GET"; |
| 3698 | request.url = GURL("https://www.example.org/"); |
| 3699 | // Ensure that proxy authentication is attempted even |
| 3700 | // when the no authentication data flag is set. |
| 3701 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3702 | request.traffic_annotation = |
| 3703 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3704 | |
| 3705 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3706 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3707 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3708 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3709 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3710 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3711 | |
| 3712 | // Since we have proxy, should try to establish tunnel. |
| 3713 | MockWrite data_writes1[] = { |
| 3714 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3715 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3716 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3717 | }; |
| 3718 | |
| 3719 | // The proxy responds to the connect with a 407, using a persistent |
| 3720 | // connection. |
| 3721 | MockRead data_reads1[] = { |
| 3722 | // No credentials. |
| 3723 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3724 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3725 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3726 | // Server hands up in the middle of the body. |
| 3727 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3728 | }; |
| 3729 | |
| 3730 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3731 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3732 | // be issuing -- the final header line contains the credentials. |
| 3733 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3734 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3735 | "Proxy-Connection: keep-alive\r\n" |
| 3736 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3737 | |
| 3738 | MockWrite("GET / HTTP/1.1\r\n" |
| 3739 | "Host: www.example.org\r\n" |
| 3740 | "Connection: keep-alive\r\n\r\n"), |
| 3741 | }; |
| 3742 | |
| 3743 | MockRead data_reads2[] = { |
| 3744 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3745 | |
| 3746 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3747 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3748 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3749 | MockRead(SYNCHRONOUS, "hello"), |
| 3750 | }; |
| 3751 | |
| 3752 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3753 | data_writes1, arraysize(data_writes1)); |
| 3754 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3755 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3756 | data_writes2, arraysize(data_writes2)); |
| 3757 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3758 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3759 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3760 | |
| 3761 | TestCompletionCallback callback; |
| 3762 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3763 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3764 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3765 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3766 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3767 | ASSERT_TRUE(response); |
| 3768 | ASSERT_TRUE(response->headers); |
| 3769 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3770 | EXPECT_EQ(407, response->headers->response_code()); |
| 3771 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3772 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3773 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3774 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3776 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3777 | ASSERT_TRUE(response); |
| 3778 | ASSERT_TRUE(response->headers); |
| 3779 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3780 | EXPECT_EQ(200, response->headers->response_code()); |
| 3781 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3782 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3783 | EXPECT_EQ("hello", body); |
| 3784 | } |
| 3785 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3786 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3787 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3788 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3789 | HttpRequestInfo request; |
| 3790 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3791 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3792 | request.traffic_annotation = |
| 3793 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3794 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3795 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3796 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3797 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3798 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3799 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3800 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3801 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3802 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3803 | // Since we have proxy, should try to establish tunnel. |
| 3804 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3805 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3806 | "Host: www.example.org:443\r\n" |
| 3807 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3808 | }; |
| 3809 | |
| 3810 | // The proxy responds to the connect with a 407. |
| 3811 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3812 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3813 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3814 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3815 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3816 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3817 | }; |
| 3818 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3819 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3820 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3821 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3823 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3824 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3825 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3827 | |
| 3828 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3829 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3831 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3832 | ASSERT_TRUE(response); |
| 3833 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3834 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3835 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3836 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3837 | |
| 3838 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3839 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3840 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3841 | |
| 3842 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3843 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3844 | } |
| 3845 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3846 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3847 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3848 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3849 | HttpRequestInfo request; |
| 3850 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3851 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3852 | request.traffic_annotation = |
| 3853 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3854 | |
| 3855 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3856 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3857 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3858 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3859 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3860 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3861 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3862 | |
| 3863 | // Since we have proxy, should try to establish tunnel. |
| 3864 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3865 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3866 | "Host: www.example.org:443\r\n" |
| 3867 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3868 | }; |
| 3869 | |
| 3870 | // The proxy responds to the connect with a 407. |
| 3871 | MockRead data_reads[] = { |
| 3872 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3873 | MockRead("X-Foo: bar\r\n"), |
| 3874 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3875 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3876 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3877 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3878 | }; |
| 3879 | |
| 3880 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3881 | arraysize(data_writes)); |
| 3882 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3883 | |
| 3884 | TestCompletionCallback callback; |
| 3885 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3886 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3887 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3888 | |
| 3889 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3890 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3891 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3892 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3893 | ASSERT_TRUE(response); |
| 3894 | ASSERT_TRUE(response->headers); |
| 3895 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3896 | EXPECT_EQ(407, response->headers->response_code()); |
| 3897 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3898 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3899 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3900 | |
| 3901 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3902 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3903 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3904 | |
| 3905 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3906 | session->CloseAllConnections(); |
| 3907 | } |
| 3908 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3909 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3910 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3911 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3912 | HttpRequestInfo request; |
| 3913 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3914 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3915 | request.traffic_annotation = |
| 3916 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3917 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3918 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3919 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3920 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3921 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3922 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3923 | MockWrite( |
| 3924 | "GET / HTTP/1.1\r\n" |
| 3925 | "Host: www.example.org\r\n" |
| 3926 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3927 | }; |
| 3928 | |
| 3929 | MockRead data_reads1[] = { |
| 3930 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3931 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3932 | // Large content-length -- won't matter, as connection will be reset. |
| 3933 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3934 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3935 | }; |
| 3936 | |
| 3937 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3938 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3939 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3940 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3941 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3942 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3943 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3944 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3945 | |
| 3946 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3947 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3948 | } |
| 3949 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3950 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3951 | // through a non-authenticating proxy. The request should fail with |
| 3952 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3953 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3954 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3955 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3956 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3957 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3958 | HttpRequestInfo request; |
| 3959 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3960 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3961 | request.traffic_annotation = |
| 3962 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3963 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3964 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3965 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3966 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3967 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3969 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3970 | // Since we have proxy, should try to establish tunnel. |
| 3971 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3972 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3973 | "Host: www.example.org:443\r\n" |
| 3974 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3975 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3976 | MockWrite("GET / HTTP/1.1\r\n" |
| 3977 | "Host: www.example.org\r\n" |
| 3978 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3979 | }; |
| 3980 | |
| 3981 | MockRead data_reads1[] = { |
| 3982 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3983 | |
| 3984 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3985 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3986 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3987 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3988 | }; |
| 3989 | |
| 3990 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3991 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3992 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3993 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3994 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3995 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3996 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3998 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3999 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4000 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4001 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4002 | |
| 4003 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4004 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4005 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4006 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4007 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4008 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4009 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4010 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4011 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4012 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4013 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4014 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4015 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4016 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4017 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4018 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4019 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4020 | HttpRequestInfo request; |
| 4021 | request.method = "GET"; |
| 4022 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4023 | request.traffic_annotation = |
| 4024 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4025 | |
| 4026 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4027 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4028 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4029 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4030 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4031 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4032 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4033 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4034 | mock_handler->set_allows_default_credentials(true); |
| 4035 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4036 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4037 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4038 | |
| 4039 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4040 | NetLog net_log; |
| 4041 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4042 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4043 | |
| 4044 | // Since we have proxy, should try to establish tunnel. |
| 4045 | MockWrite data_writes1[] = { |
| 4046 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4047 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4048 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4049 | }; |
| 4050 | |
| 4051 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4052 | // connection. |
| 4053 | MockRead data_reads1[] = { |
| 4054 | // No credentials. |
| 4055 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4056 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4057 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4058 | }; |
| 4059 | |
| 4060 | // Since the first connection couldn't be reused, need to establish another |
| 4061 | // once given credentials. |
| 4062 | MockWrite data_writes2[] = { |
| 4063 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4064 | // be issuing -- the final header line contains the credentials. |
| 4065 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4066 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4067 | "Proxy-Connection: keep-alive\r\n" |
| 4068 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4069 | |
| 4070 | MockWrite("GET / HTTP/1.1\r\n" |
| 4071 | "Host: www.example.org\r\n" |
| 4072 | "Connection: keep-alive\r\n\r\n"), |
| 4073 | }; |
| 4074 | |
| 4075 | MockRead data_reads2[] = { |
| 4076 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4077 | |
| 4078 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4079 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4080 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4081 | MockRead(SYNCHRONOUS, "hello"), |
| 4082 | }; |
| 4083 | |
| 4084 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4085 | data_writes1, arraysize(data_writes1)); |
| 4086 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4087 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4088 | data_writes2, arraysize(data_writes2)); |
| 4089 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4090 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4091 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4092 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4093 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4094 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4095 | |
| 4096 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4097 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4098 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4099 | |
| 4100 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4101 | ASSERT_TRUE(response); |
| 4102 | ASSERT_TRUE(response->headers); |
| 4103 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4104 | EXPECT_EQ(407, response->headers->response_code()); |
| 4105 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4106 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4107 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4108 | |
| 4109 | LoadTimingInfo load_timing_info; |
| 4110 | // CONNECT requests and responses are handled at the connect job level, so |
| 4111 | // the transaction does not yet have a connection. |
| 4112 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4113 | |
| 4114 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4115 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4116 | response = trans->GetResponseInfo(); |
| 4117 | ASSERT_TRUE(response); |
| 4118 | ASSERT_TRUE(response->headers); |
| 4119 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4120 | EXPECT_EQ(200, response->headers->response_code()); |
| 4121 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4122 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4123 | |
| 4124 | // The password prompt info should not be set. |
| 4125 | EXPECT_FALSE(response->auth_challenge); |
| 4126 | |
| 4127 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4128 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4129 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4130 | |
| 4131 | trans.reset(); |
| 4132 | session->CloseAllConnections(); |
| 4133 | } |
| 4134 | |
| 4135 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4136 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4137 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4138 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4139 | HttpRequestInfo request; |
| 4140 | request.method = "GET"; |
| 4141 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4142 | request.traffic_annotation = |
| 4143 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4144 | |
| 4145 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4146 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4147 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4148 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4149 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4150 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4151 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4152 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4153 | mock_handler->set_allows_default_credentials(true); |
| 4154 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4155 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4156 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4157 | |
| 4158 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4159 | NetLog net_log; |
| 4160 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4161 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4162 | |
| 4163 | // Should try to establish tunnel. |
| 4164 | MockWrite data_writes1[] = { |
| 4165 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4166 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4167 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4168 | |
| 4169 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4170 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4171 | "Proxy-Connection: keep-alive\r\n" |
| 4172 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4173 | }; |
| 4174 | |
| 4175 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4176 | // connection. |
| 4177 | MockRead data_reads1[] = { |
| 4178 | // No credentials. |
| 4179 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4180 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4181 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4182 | }; |
| 4183 | |
| 4184 | // Since the first connection was closed, need to establish another once given |
| 4185 | // credentials. |
| 4186 | MockWrite data_writes2[] = { |
| 4187 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4188 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4189 | "Proxy-Connection: keep-alive\r\n" |
| 4190 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4191 | |
| 4192 | MockWrite("GET / HTTP/1.1\r\n" |
| 4193 | "Host: www.example.org\r\n" |
| 4194 | "Connection: keep-alive\r\n\r\n"), |
| 4195 | }; |
| 4196 | |
| 4197 | MockRead data_reads2[] = { |
| 4198 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4199 | |
| 4200 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4201 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4202 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4203 | MockRead(SYNCHRONOUS, "hello"), |
| 4204 | }; |
| 4205 | |
| 4206 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4207 | data_writes1, arraysize(data_writes1)); |
| 4208 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4209 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4210 | data_writes2, arraysize(data_writes2)); |
| 4211 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4212 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4213 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4214 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4215 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4216 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4217 | |
| 4218 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4219 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4220 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4221 | |
| 4222 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4223 | ASSERT_TRUE(response); |
| 4224 | ASSERT_TRUE(response->headers); |
| 4225 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4226 | EXPECT_EQ(407, response->headers->response_code()); |
| 4227 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4228 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4229 | EXPECT_FALSE(response->auth_challenge); |
| 4230 | |
| 4231 | LoadTimingInfo load_timing_info; |
| 4232 | // CONNECT requests and responses are handled at the connect job level, so |
| 4233 | // the transaction does not yet have a connection. |
| 4234 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4235 | |
| 4236 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4237 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4238 | |
| 4239 | response = trans->GetResponseInfo(); |
| 4240 | ASSERT_TRUE(response); |
| 4241 | ASSERT_TRUE(response->headers); |
| 4242 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4243 | EXPECT_EQ(200, response->headers->response_code()); |
| 4244 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4245 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4246 | |
| 4247 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4248 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4249 | |
| 4250 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4251 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4252 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4253 | |
| 4254 | trans.reset(); |
| 4255 | session->CloseAllConnections(); |
| 4256 | } |
| 4257 | |
| 4258 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4259 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4260 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4261 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4262 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4263 | HttpRequestInfo request; |
| 4264 | request.method = "GET"; |
| 4265 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4266 | request.traffic_annotation = |
| 4267 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4268 | |
| 4269 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4270 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4271 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4272 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4273 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4274 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4275 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4276 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4277 | mock_handler->set_allows_default_credentials(true); |
| 4278 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4279 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4280 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4281 | |
| 4282 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4283 | NetLog net_log; |
| 4284 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4285 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4286 | |
| 4287 | // Should try to establish tunnel. |
| 4288 | MockWrite data_writes1[] = { |
| 4289 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4290 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4291 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4292 | |
| 4293 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4294 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4295 | "Proxy-Connection: keep-alive\r\n" |
| 4296 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4297 | }; |
| 4298 | |
| 4299 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4300 | // second request is sent. |
| 4301 | MockRead data_reads1[] = { |
| 4302 | // No credentials. |
| 4303 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4304 | MockRead("Content-Length: 0\r\n"), |
| 4305 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4306 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4307 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4308 | }; |
| 4309 | |
| 4310 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4311 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4312 | // request. |
| 4313 | MockWrite data_writes2[] = { |
| 4314 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4315 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4316 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4317 | }; |
| 4318 | |
| 4319 | // The proxy, having had more than enough of us, just hangs up. |
| 4320 | MockRead data_reads2[] = { |
| 4321 | // No credentials. |
| 4322 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4323 | }; |
| 4324 | |
| 4325 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4326 | data_writes1, arraysize(data_writes1)); |
| 4327 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4328 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4329 | data_writes2, arraysize(data_writes2)); |
| 4330 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4331 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4332 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4333 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4334 | |
| 4335 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4336 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4337 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4338 | |
| 4339 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4340 | ASSERT_TRUE(response); |
| 4341 | ASSERT_TRUE(response->headers); |
| 4342 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4343 | EXPECT_EQ(407, response->headers->response_code()); |
| 4344 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4345 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4346 | EXPECT_FALSE(response->auth_challenge); |
| 4347 | |
| 4348 | LoadTimingInfo load_timing_info; |
| 4349 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4350 | |
| 4351 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4352 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4353 | |
| 4354 | trans.reset(); |
| 4355 | session->CloseAllConnections(); |
| 4356 | } |
| 4357 | |
| 4358 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4359 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4360 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4361 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4362 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4363 | HttpRequestInfo request; |
| 4364 | request.method = "GET"; |
| 4365 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4366 | request.traffic_annotation = |
| 4367 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4368 | |
| 4369 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4370 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4371 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4372 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4373 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4374 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4375 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4376 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4377 | mock_handler->set_allows_default_credentials(true); |
| 4378 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4379 | HttpAuth::AUTH_PROXY); |
| 4380 | // Add another handler for the second challenge. It supports default |
| 4381 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4382 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4383 | mock_handler->set_allows_default_credentials(true); |
| 4384 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4385 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4386 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4387 | |
| 4388 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4389 | NetLog net_log; |
| 4390 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4391 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4392 | |
| 4393 | // Should try to establish tunnel. |
| 4394 | MockWrite data_writes1[] = { |
| 4395 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4396 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4397 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4398 | }; |
| 4399 | |
| 4400 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4401 | // connection. |
| 4402 | MockRead data_reads1[] = { |
| 4403 | // No credentials. |
| 4404 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4405 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4406 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4407 | }; |
| 4408 | |
| 4409 | // Since the first connection was closed, need to establish another once given |
| 4410 | // credentials. |
| 4411 | MockWrite data_writes2[] = { |
| 4412 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4413 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4414 | "Proxy-Connection: keep-alive\r\n" |
| 4415 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4416 | }; |
| 4417 | |
| 4418 | MockRead data_reads2[] = { |
| 4419 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4420 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4421 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4422 | }; |
| 4423 | |
| 4424 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4425 | data_writes1, arraysize(data_writes1)); |
| 4426 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4427 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4428 | data_writes2, arraysize(data_writes2)); |
| 4429 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4430 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4431 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4432 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4433 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4434 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4435 | |
| 4436 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4437 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4438 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4439 | |
| 4440 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4441 | ASSERT_TRUE(response); |
| 4442 | ASSERT_TRUE(response->headers); |
| 4443 | EXPECT_EQ(407, response->headers->response_code()); |
| 4444 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4445 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4446 | EXPECT_FALSE(response->auth_challenge); |
| 4447 | |
| 4448 | LoadTimingInfo load_timing_info; |
| 4449 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4450 | |
| 4451 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4452 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4453 | response = trans->GetResponseInfo(); |
| 4454 | ASSERT_TRUE(response); |
| 4455 | ASSERT_TRUE(response->headers); |
| 4456 | EXPECT_EQ(407, response->headers->response_code()); |
| 4457 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4458 | EXPECT_TRUE(response->auth_challenge); |
| 4459 | |
| 4460 | trans.reset(); |
| 4461 | session->CloseAllConnections(); |
| 4462 | } |
| 4463 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4464 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4465 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4466 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4467 | // authentication handshake can continue with the same scheme but with a |
| 4468 | // different identity. |
| 4469 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4470 | HttpRequestInfo request; |
| 4471 | request.method = "GET"; |
| 4472 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4473 | request.traffic_annotation = |
| 4474 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4475 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4476 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4477 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4478 | |
| 4479 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4480 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4481 | mock_handler->set_allows_default_credentials(true); |
| 4482 | mock_handler->set_allows_explicit_credentials(true); |
| 4483 | mock_handler->set_connection_based(true); |
| 4484 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4485 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4486 | HttpAuth::AUTH_SERVER); |
| 4487 | |
| 4488 | // Add another handler for the second challenge. It supports default |
| 4489 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4490 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4491 | mock_handler->set_allows_default_credentials(true); |
| 4492 | mock_handler->set_allows_explicit_credentials(true); |
| 4493 | mock_handler->set_connection_based(true); |
| 4494 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4495 | HttpAuth::AUTH_SERVER); |
| 4496 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4497 | |
| 4498 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4499 | |
| 4500 | MockWrite data_writes1[] = { |
| 4501 | MockWrite("GET / HTTP/1.1\r\n" |
| 4502 | "Host: www.example.org\r\n" |
| 4503 | "Connection: keep-alive\r\n\r\n"), |
| 4504 | }; |
| 4505 | |
| 4506 | MockRead data_reads1[] = { |
| 4507 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4508 | "WWW-Authenticate: Mock\r\n" |
| 4509 | "Connection: keep-alive\r\n\r\n"), |
| 4510 | }; |
| 4511 | |
| 4512 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4513 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4514 | // transaction procceds without an authorization header. |
| 4515 | MockWrite data_writes2[] = { |
| 4516 | MockWrite("GET / HTTP/1.1\r\n" |
| 4517 | "Host: www.example.org\r\n" |
| 4518 | "Connection: keep-alive\r\n\r\n"), |
| 4519 | }; |
| 4520 | |
| 4521 | MockRead data_reads2[] = { |
| 4522 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4523 | "WWW-Authenticate: Mock\r\n" |
| 4524 | "Connection: keep-alive\r\n\r\n"), |
| 4525 | }; |
| 4526 | |
| 4527 | MockWrite data_writes3[] = { |
| 4528 | MockWrite("GET / HTTP/1.1\r\n" |
| 4529 | "Host: www.example.org\r\n" |
| 4530 | "Connection: keep-alive\r\n" |
| 4531 | "Authorization: auth_token\r\n\r\n"), |
| 4532 | }; |
| 4533 | |
| 4534 | MockRead data_reads3[] = { |
| 4535 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4536 | "Content-Length: 5\r\n" |
| 4537 | "Content-Type: text/plain\r\n" |
| 4538 | "Connection: keep-alive\r\n\r\n" |
| 4539 | "Hello"), |
| 4540 | }; |
| 4541 | |
| 4542 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4543 | data_writes1, arraysize(data_writes1)); |
| 4544 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4545 | |
| 4546 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4547 | data_writes2, arraysize(data_writes2)); |
| 4548 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4549 | |
| 4550 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4551 | data_writes3, arraysize(data_writes3)); |
| 4552 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4553 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4554 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4555 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4556 | |
| 4557 | TestCompletionCallback callback; |
| 4558 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4559 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4560 | |
| 4561 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4562 | ASSERT_TRUE(response); |
| 4563 | ASSERT_TRUE(response->headers); |
| 4564 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4565 | |
| 4566 | // The following three tests assert that an authentication challenge was |
| 4567 | // received and that the stack is ready to respond to the challenge using |
| 4568 | // ambient credentials. |
| 4569 | EXPECT_EQ(401, response->headers->response_code()); |
| 4570 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4571 | EXPECT_FALSE(response->auth_challenge); |
| 4572 | |
| 4573 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4574 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4575 | response = trans->GetResponseInfo(); |
| 4576 | ASSERT_TRUE(response); |
| 4577 | ASSERT_TRUE(response->headers); |
| 4578 | |
| 4579 | // The following three tests assert that an authentication challenge was |
| 4580 | // received and that the stack needs explicit credentials before it is ready |
| 4581 | // to respond to the challenge. |
| 4582 | EXPECT_EQ(401, response->headers->response_code()); |
| 4583 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4584 | EXPECT_TRUE(response->auth_challenge); |
| 4585 | |
| 4586 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4587 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4588 | response = trans->GetResponseInfo(); |
| 4589 | ASSERT_TRUE(response); |
| 4590 | ASSERT_TRUE(response->headers); |
| 4591 | EXPECT_EQ(200, response->headers->response_code()); |
| 4592 | |
| 4593 | trans.reset(); |
| 4594 | session->CloseAllConnections(); |
| 4595 | } |
| 4596 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4597 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4598 | // schemes, based on the path of the URL being requests. |
| 4599 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4600 | public: |
| 4601 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4602 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4603 | |
| 4604 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4605 | |
| 4606 | static HostPortPair ProxyHostPortPair() { |
| 4607 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4608 | } |
| 4609 | |
| 4610 | // ProxyResolver implementation. |
| 4611 | int GetProxyForURL(const GURL& url, |
| 4612 | ProxyInfo* results, |
| 4613 | const CompletionCallback& callback, |
| 4614 | std::unique_ptr<Request>* request, |
| 4615 | const NetLogWithSource& /*net_log*/) override { |
| 4616 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4617 | results->set_traffic_annotation( |
| 4618 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4619 | if (url.path() == "/socks4") { |
| 4620 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4621 | return OK; |
| 4622 | } |
| 4623 | if (url.path() == "/socks5") { |
| 4624 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4625 | return OK; |
| 4626 | } |
| 4627 | if (url.path() == "/http") { |
| 4628 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4629 | return OK; |
| 4630 | } |
| 4631 | if (url.path() == "/https") { |
| 4632 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4633 | return OK; |
| 4634 | } |
| 4635 | NOTREACHED(); |
| 4636 | return ERR_NOT_IMPLEMENTED; |
| 4637 | } |
| 4638 | |
| 4639 | private: |
| 4640 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4641 | }; |
| 4642 | |
| 4643 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4644 | : public ProxyResolverFactory { |
| 4645 | public: |
| 4646 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4647 | : ProxyResolverFactory(false) {} |
| 4648 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4649 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4650 | std::unique_ptr<ProxyResolver>* resolver, |
| 4651 | const CompletionCallback& callback, |
| 4652 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4653 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4654 | return OK; |
| 4655 | } |
| 4656 | |
| 4657 | private: |
| 4658 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4659 | }; |
| 4660 | |
| 4661 | // Check that when different proxy schemes are all applied to a proxy at the |
| 4662 | // same address, the sonnections are not grouped together. i.e., a request to |
| 4663 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4664 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4665 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4666 | session_deps_.proxy_resolution_service = |
| 4667 | std::make_unique<ProxyResolutionService>( |
| 4668 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4669 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4670 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4671 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4672 | |
| 4673 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4674 | |
| 4675 | MockWrite socks_writes[] = { |
| 4676 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4677 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4678 | MockWrite(SYNCHRONOUS, |
| 4679 | "GET /socks4 HTTP/1.1\r\n" |
| 4680 | "Host: test\r\n" |
| 4681 | "Connection: keep-alive\r\n\r\n"), |
| 4682 | }; |
| 4683 | MockRead socks_reads[] = { |
| 4684 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4685 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4686 | "Connection: keep-alive\r\n" |
| 4687 | "Content-Length: 15\r\n\r\n" |
| 4688 | "SOCKS4 Response"), |
| 4689 | }; |
| 4690 | StaticSocketDataProvider socks_data(socks_reads, arraysize(socks_reads), |
| 4691 | socks_writes, arraysize(socks_writes)); |
| 4692 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4693 | |
| 4694 | const char kSOCKS5Request[] = { |
| 4695 | 0x05, // Version |
| 4696 | 0x01, // Command (CONNECT) |
| 4697 | 0x00, // Reserved |
| 4698 | 0x03, // Address type (DOMAINNAME) |
| 4699 | 0x04, // Length of domain (4) |
| 4700 | 't', 'e', 's', 't', // Domain string |
| 4701 | 0x00, 0x50, // 16-bit port (80) |
| 4702 | }; |
| 4703 | MockWrite socks5_writes[] = { |
| 4704 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
| 4705 | MockWrite(ASYNC, kSOCKS5Request, arraysize(kSOCKS5Request)), |
| 4706 | MockWrite(SYNCHRONOUS, |
| 4707 | "GET /socks5 HTTP/1.1\r\n" |
| 4708 | "Host: test\r\n" |
| 4709 | "Connection: keep-alive\r\n\r\n"), |
| 4710 | }; |
| 4711 | MockRead socks5_reads[] = { |
| 4712 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4713 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4714 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4715 | "Connection: keep-alive\r\n" |
| 4716 | "Content-Length: 15\r\n\r\n" |
| 4717 | "SOCKS5 Response"), |
| 4718 | }; |
| 4719 | StaticSocketDataProvider socks5_data(socks5_reads, arraysize(socks5_reads), |
| 4720 | socks5_writes, arraysize(socks5_writes)); |
| 4721 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 4722 | |
| 4723 | MockWrite http_writes[] = { |
| 4724 | MockWrite(SYNCHRONOUS, |
| 4725 | "GET http://test/http HTTP/1.1\r\n" |
| 4726 | "Host: test\r\n" |
| 4727 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4728 | }; |
| 4729 | MockRead http_reads[] = { |
| 4730 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4731 | "Proxy-Connection: keep-alive\r\n" |
| 4732 | "Content-Length: 13\r\n\r\n" |
| 4733 | "HTTP Response"), |
| 4734 | }; |
| 4735 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 4736 | http_writes, arraysize(http_writes)); |
| 4737 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 4738 | |
| 4739 | MockWrite https_writes[] = { |
| 4740 | MockWrite(SYNCHRONOUS, |
| 4741 | "GET http://test/https HTTP/1.1\r\n" |
| 4742 | "Host: test\r\n" |
| 4743 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4744 | }; |
| 4745 | MockRead https_reads[] = { |
| 4746 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4747 | "Proxy-Connection: keep-alive\r\n" |
| 4748 | "Content-Length: 14\r\n\r\n" |
| 4749 | "HTTPS Response"), |
| 4750 | }; |
| 4751 | StaticSocketDataProvider https_data(https_reads, arraysize(https_reads), |
| 4752 | https_writes, arraysize(https_writes)); |
| 4753 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 4754 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 4755 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4756 | |
| 4757 | struct TestCase { |
| 4758 | GURL url; |
| 4759 | std::string expected_response; |
| 4760 | // How many idle sockets there should be in the SOCKS proxy socket pool |
| 4761 | // after the test. |
| 4762 | int expected_idle_socks_sockets; |
| 4763 | // How many idle sockets there should be in the HTTP proxy socket pool after |
| 4764 | // the test. |
| 4765 | int expected_idle_http_sockets; |
| 4766 | } const kTestCases[] = { |
| 4767 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0}, |
| 4768 | {GURL("http://test/socks5"), "SOCKS5 Response", 2, 0}, |
| 4769 | {GURL("http://test/http"), "HTTP Response", 2, 1}, |
| 4770 | {GURL("http://test/https"), "HTTPS Response", 2, 2}, |
| 4771 | }; |
| 4772 | |
| 4773 | for (const auto& test_case : kTestCases) { |
| 4774 | HttpRequestInfo request; |
| 4775 | request.method = "GET"; |
| 4776 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4777 | request.traffic_annotation = |
| 4778 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4779 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 4780 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 4781 | session.get()); |
| 4782 | TestCompletionCallback callback; |
| 4783 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4784 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4785 | |
| 4786 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4787 | ASSERT_TRUE(response); |
| 4788 | ASSERT_TRUE(response->headers); |
| 4789 | EXPECT_EQ(200, response->headers->response_code()); |
| 4790 | std::string response_data; |
| 4791 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4792 | EXPECT_EQ(test_case.expected_response, response_data); |
| 4793 | |
| 4794 | // Return the socket to the socket pool, so can make sure it's not used for |
| 4795 | // the next requests. |
| 4796 | trans.reset(); |
| 4797 | base::RunLoop().RunUntilIdle(); |
| 4798 | |
| 4799 | // Check the number of idle sockets in the pool, to make sure that used |
| 4800 | // sockets are indeed being returned to the socket pool. If each request |
| 4801 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 4802 | // pass. |
| 4803 | EXPECT_EQ( |
| 4804 | test_case.expected_idle_socks_sockets, |
| 4805 | session |
| 4806 | ->GetSocketPoolForSOCKSProxy( |
| 4807 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4808 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4809 | ->IdleSocketCount()); |
| 4810 | EXPECT_EQ( |
| 4811 | test_case.expected_idle_http_sockets, |
| 4812 | session |
| 4813 | ->GetSocketPoolForHTTPProxy( |
| 4814 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4815 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4816 | ->IdleSocketCount()); |
| 4817 | } |
| 4818 | } |
| 4819 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4820 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4821 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4822 | HttpRequestInfo request1; |
| 4823 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4824 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4825 | request1.traffic_annotation = |
| 4826 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4827 | |
| 4828 | HttpRequestInfo request2; |
| 4829 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4830 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4831 | request2.traffic_annotation = |
| 4832 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4833 | |
| 4834 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4835 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4836 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4837 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4838 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4839 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4840 | |
| 4841 | // Since we have proxy, should try to establish tunnel. |
| 4842 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4843 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4844 | "Host: www.example.org:443\r\n" |
| 4845 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4846 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4847 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4848 | "Host: www.example.org\r\n" |
| 4849 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4850 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4851 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4852 | "Host: www.example.org\r\n" |
| 4853 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4854 | }; |
| 4855 | |
| 4856 | // The proxy responds to the connect with a 407, using a persistent |
| 4857 | // connection. |
| 4858 | MockRead data_reads1[] = { |
| 4859 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4860 | |
| 4861 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4862 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4863 | MockRead(SYNCHRONOUS, "1"), |
| 4864 | |
| 4865 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4866 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4867 | MockRead(SYNCHRONOUS, "22"), |
| 4868 | }; |
| 4869 | |
| 4870 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4871 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4872 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4873 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4874 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4875 | |
| 4876 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4877 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4878 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4879 | |
| 4880 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4882 | |
| 4883 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4884 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4885 | |
| 4886 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4887 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4888 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4889 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4890 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4891 | |
| 4892 | LoadTimingInfo load_timing_info1; |
| 4893 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4894 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4895 | |
| 4896 | trans1.reset(); |
| 4897 | |
| 4898 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4899 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4900 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4901 | |
| 4902 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4903 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4904 | |
| 4905 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4906 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4907 | |
| 4908 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4909 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4910 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4911 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4912 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4913 | |
| 4914 | LoadTimingInfo load_timing_info2; |
| 4915 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4916 | TestLoadTimingReused(load_timing_info2); |
| 4917 | |
| 4918 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4919 | |
| 4920 | trans2.reset(); |
| 4921 | session->CloseAllConnections(); |
| 4922 | } |
| 4923 | |
| 4924 | // 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] | 4925 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4926 | HttpRequestInfo request1; |
| 4927 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4928 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4929 | request1.traffic_annotation = |
| 4930 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4931 | |
| 4932 | HttpRequestInfo request2; |
| 4933 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4934 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4935 | request2.traffic_annotation = |
| 4936 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4937 | |
| 4938 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4939 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4940 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4941 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4942 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4943 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4944 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4945 | |
| 4946 | // Since we have proxy, should try to establish tunnel. |
| 4947 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4948 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4949 | "Host: www.example.org:443\r\n" |
| 4950 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4951 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4952 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4953 | "Host: www.example.org\r\n" |
| 4954 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4955 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4956 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4957 | "Host: www.example.org\r\n" |
| 4958 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4959 | }; |
| 4960 | |
| 4961 | // The proxy responds to the connect with a 407, using a persistent |
| 4962 | // connection. |
| 4963 | MockRead data_reads1[] = { |
| 4964 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4965 | |
| 4966 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4967 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4968 | MockRead(SYNCHRONOUS, "1"), |
| 4969 | |
| 4970 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4971 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4972 | MockRead(SYNCHRONOUS, "22"), |
| 4973 | }; |
| 4974 | |
| 4975 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4976 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4977 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4978 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4979 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4980 | |
| 4981 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4982 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4983 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4984 | |
| 4985 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4986 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4987 | |
| 4988 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4989 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4990 | |
| 4991 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4992 | ASSERT_TRUE(response1); |
| 4993 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4994 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4995 | |
| 4996 | LoadTimingInfo load_timing_info1; |
| 4997 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4998 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4999 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5000 | |
| 5001 | trans1.reset(); |
| 5002 | |
| 5003 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5004 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5005 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5006 | |
| 5007 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5008 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5009 | |
| 5010 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5011 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5012 | |
| 5013 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5014 | ASSERT_TRUE(response2); |
| 5015 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5016 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5017 | |
| 5018 | LoadTimingInfo load_timing_info2; |
| 5019 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5020 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5021 | |
| 5022 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5023 | |
| 5024 | trans2.reset(); |
| 5025 | session->CloseAllConnections(); |
| 5026 | } |
| 5027 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5028 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5029 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5030 | HttpRequestInfo request; |
| 5031 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5032 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5033 | request.traffic_annotation = |
| 5034 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5035 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5036 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5037 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5038 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5039 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5040 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5041 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5042 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5043 | // Since we have proxy, should use full url |
| 5044 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5045 | MockWrite( |
| 5046 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5047 | "Host: www.example.org\r\n" |
| 5048 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5049 | }; |
| 5050 | |
| 5051 | MockRead data_reads1[] = { |
| 5052 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5053 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5054 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5055 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5056 | }; |
| 5057 | |
| 5058 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5059 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5060 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5061 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5062 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5063 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5064 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5065 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5066 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5067 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5068 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5069 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5070 | |
| 5071 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5072 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5073 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5074 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5075 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5076 | TestLoadTimingNotReused(load_timing_info, |
| 5077 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5078 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5079 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5080 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5081 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5082 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5083 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5084 | EXPECT_EQ(200, response->headers->response_code()); |
| 5085 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5086 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5087 | |
| 5088 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5089 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5090 | } |
| 5091 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5092 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5093 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5094 | HttpRequestInfo request; |
| 5095 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5096 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5097 | request.traffic_annotation = |
| 5098 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5099 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5100 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5101 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5102 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5103 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5104 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5105 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5106 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5107 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5108 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5109 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5110 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5111 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5112 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5113 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5114 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5115 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5116 | }; |
| 5117 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5118 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5119 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5120 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5121 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5122 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5123 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5125 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5126 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5127 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5128 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5129 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5130 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5131 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5132 | |
| 5133 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5134 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5135 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5136 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5137 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5138 | TestLoadTimingNotReused(load_timing_info, |
| 5139 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5140 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5141 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5142 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5143 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5144 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5145 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5146 | |
| 5147 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5148 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5149 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5150 | } |
| 5151 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5152 | // Verifies that a session which races and wins against the owning transaction |
| 5153 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5154 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5155 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5156 | HttpRequestInfo request; |
| 5157 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5158 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5159 | request.traffic_annotation = |
| 5160 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5161 | |
| 5162 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5163 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5164 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5165 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5166 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5167 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5168 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5169 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5170 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5171 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5172 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5173 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5174 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5175 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5176 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5177 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5178 | }; |
| 5179 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5180 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5181 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5182 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5183 | |
| 5184 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5185 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5186 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5187 | |
| 5188 | TestCompletionCallback callback1; |
| 5189 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5190 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5191 | |
| 5192 | // Stall the hostname resolution begun by the transaction. |
| 5193 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 5194 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5195 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5196 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5197 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5198 | |
| 5199 | // Race a session to the proxy, which completes first. |
| 5200 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5201 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
| 5202 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5203 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5204 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5205 | |
| 5206 | // Unstall the resolution begun by the transaction. |
| 5207 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5208 | session_deps_.host_resolver->ResolveAllPending(); |
| 5209 | |
| 5210 | EXPECT_FALSE(callback1.have_result()); |
| 5211 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5212 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5213 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5214 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5215 | ASSERT_TRUE(response); |
| 5216 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5217 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5218 | |
| 5219 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5220 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5221 | EXPECT_EQ(kUploadData, response_data); |
| 5222 | } |
| 5223 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5224 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5225 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5226 | HttpRequestInfo request; |
| 5227 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5228 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5229 | request.traffic_annotation = |
| 5230 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5231 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5232 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5233 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5234 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5235 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5236 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5237 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5238 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5239 | // The first request will be a bare GET, the second request will be a |
| 5240 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5241 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5242 | SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5243 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5244 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5245 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5246 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5247 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5248 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 5249 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5250 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5251 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5252 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5253 | }; |
| 5254 | |
| 5255 | // The first response is a 407 proxy authentication challenge, and the second |
| 5256 | // response will be a 200 response since the second request includes a valid |
| 5257 | // Authorization header. |
| 5258 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5259 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5260 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5261 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 5262 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5263 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 5264 | SpdySerializedFrame body_authentication( |
| 5265 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5266 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5267 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5268 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5269 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5270 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5271 | CreateMockRead(resp_data, 4), |
| 5272 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5273 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5274 | }; |
| 5275 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5276 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5277 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5278 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5279 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5280 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5281 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5282 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5283 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5284 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5285 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5286 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5287 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5288 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5289 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5290 | |
| 5291 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5292 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5293 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5294 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5295 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5296 | ASSERT_TRUE(response); |
| 5297 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5298 | EXPECT_EQ(407, response->headers->response_code()); |
| 5299 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5300 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5301 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5302 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5304 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5305 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5306 | |
| 5307 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5308 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5309 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5310 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5311 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5312 | ASSERT_TRUE(response_restart); |
| 5313 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5314 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5315 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5316 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5317 | } |
| 5318 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5319 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5320 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5321 | HttpRequestInfo request; |
| 5322 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5323 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5324 | request.traffic_annotation = |
| 5325 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5326 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5327 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5328 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5329 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5330 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5331 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5332 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5333 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5334 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5335 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5336 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5337 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5338 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5339 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5340 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5341 | const char get[] = |
| 5342 | "GET / HTTP/1.1\r\n" |
| 5343 | "Host: www.example.org\r\n" |
| 5344 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5345 | SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5346 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5347 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5348 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5349 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5350 | SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5351 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5352 | SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5353 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5354 | SpdySerializedFrame window_update( |
| 5355 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5356 | |
| 5357 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5358 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5359 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5360 | }; |
| 5361 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5362 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5363 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5364 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5365 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5366 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5367 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5368 | }; |
| 5369 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5370 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5371 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5372 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5373 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5374 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5375 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5376 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5377 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5378 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5379 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5380 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5381 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5382 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5383 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5384 | |
| 5385 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5386 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5387 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5388 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5389 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5390 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5391 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5392 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5393 | ASSERT_TRUE(response); |
| 5394 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5395 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5396 | |
| 5397 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5398 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5399 | EXPECT_EQ("1234567890", response_data); |
| 5400 | } |
| 5401 | |
| 5402 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5403 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5404 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5405 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5406 | HttpRequestInfo request; |
| 5407 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5408 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5409 | request.traffic_annotation = |
| 5410 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5411 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5412 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5413 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5414 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5415 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5416 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5417 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5418 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5419 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5420 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5421 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5422 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5423 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5424 | // fetch https://www.example.org/ via SPDY |
| 5425 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5426 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5427 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5428 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5429 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5430 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5431 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5432 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5433 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5434 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5435 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5436 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5437 | SpdySerializedFrame window_update_get_resp( |
| 5438 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 5439 | SpdySerializedFrame window_update_body( |
| 5440 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5441 | |
| 5442 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5443 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5444 | CreateMockWrite(window_update_get_resp, 6), |
| 5445 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5446 | }; |
| 5447 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5448 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5449 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5450 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5451 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5452 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5453 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5454 | }; |
| 5455 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5456 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5457 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5458 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5459 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5460 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5461 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5463 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5464 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5465 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5466 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5467 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5468 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5469 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5471 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5472 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5473 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5474 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5475 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5476 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5477 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5478 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5479 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5480 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5481 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5482 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5483 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5484 | ASSERT_TRUE(response); |
| 5485 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5486 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5487 | |
| 5488 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5489 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5490 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5491 | } |
| 5492 | |
| 5493 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5494 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5495 | HttpRequestInfo request; |
| 5496 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5497 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5498 | request.traffic_annotation = |
| 5499 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5500 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5501 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5502 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5503 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5504 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5505 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5506 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5507 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5508 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5509 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5510 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5511 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5512 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5513 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5514 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5515 | |
| 5516 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5517 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5518 | }; |
| 5519 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5520 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5521 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5522 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5523 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5524 | }; |
| 5525 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5526 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5527 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5528 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5529 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5530 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5531 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5532 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5533 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5534 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5535 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5536 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5537 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5538 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5539 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5540 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5541 | |
| 5542 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5543 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5544 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5545 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5546 | } |
| 5547 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5548 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5549 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5550 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5551 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5552 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5553 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5554 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5555 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5556 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5557 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5558 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5559 | |
| 5560 | HttpRequestInfo request1; |
| 5561 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5562 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5563 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5564 | request1.traffic_annotation = |
| 5565 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5566 | |
| 5567 | HttpRequestInfo request2; |
| 5568 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5569 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5570 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5571 | request2.traffic_annotation = |
| 5572 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5573 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5574 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5575 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5576 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5577 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5578 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5579 | // Fetch https://www.example.org/ via HTTP. |
| 5580 | const char get1[] = |
| 5581 | "GET / HTTP/1.1\r\n" |
| 5582 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5583 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5584 | SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5585 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5586 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5587 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5588 | SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5589 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5590 | SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5591 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5592 | SpdySerializedFrame window_update( |
| 5593 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5594 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5595 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5596 | SpdyHeaderBlock connect2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 5597 | connect2_block[kHttp2MethodHeader] = "CONNECT"; |
| 5598 | connect2_block[kHttp2AuthorityHeader] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5599 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5600 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5601 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5602 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5603 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5604 | // Fetch https://mail.example.org/ via HTTP. |
| 5605 | const char get2[] = |
| 5606 | "GET / HTTP/1.1\r\n" |
| 5607 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5608 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5609 | SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5610 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5611 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5612 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5613 | SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5614 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5615 | SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5616 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5617 | |
| 5618 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5619 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5620 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5621 | }; |
| 5622 | |
| 5623 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5624 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5625 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5626 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5627 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5628 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5629 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5630 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5631 | }; |
| 5632 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5633 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5634 | arraysize(spdy_writes)); |
| 5635 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5636 | |
| 5637 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5638 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5639 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5640 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5641 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5642 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5643 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5644 | |
| 5645 | TestCompletionCallback callback; |
| 5646 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5647 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5648 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5649 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5650 | |
| 5651 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5652 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5653 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5654 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5655 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5656 | ASSERT_TRUE(response); |
| 5657 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5658 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5659 | |
| 5660 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5661 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5662 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5663 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5664 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5665 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5666 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5667 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5668 | |
| 5669 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5670 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5671 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5672 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5673 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5674 | |
| 5675 | // The requests should have different IDs, since they each are using their own |
| 5676 | // separate stream. |
| 5677 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5678 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5679 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5680 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5681 | } |
| 5682 | |
| 5683 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5684 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5685 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5686 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5687 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5688 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5689 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5690 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5691 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5692 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5693 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5694 | |
| 5695 | HttpRequestInfo request1; |
| 5696 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5697 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5698 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5699 | request1.traffic_annotation = |
| 5700 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5701 | |
| 5702 | HttpRequestInfo request2; |
| 5703 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5704 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5705 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5706 | request2.traffic_annotation = |
| 5707 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5708 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5709 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5710 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5711 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5712 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5713 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5714 | // Fetch https://www.example.org/ via HTTP. |
| 5715 | const char get1[] = |
| 5716 | "GET / HTTP/1.1\r\n" |
| 5717 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5718 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5719 | SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5720 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5721 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5722 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5723 | SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5724 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5725 | SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5726 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5727 | SpdySerializedFrame window_update( |
| 5728 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5729 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5730 | // Fetch https://www.example.org/2 via HTTP. |
| 5731 | const char get2[] = |
| 5732 | "GET /2 HTTP/1.1\r\n" |
| 5733 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5734 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5735 | SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5736 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5737 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5738 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5739 | SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5740 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5741 | SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5742 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5743 | |
| 5744 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5745 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5746 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5747 | }; |
| 5748 | |
| 5749 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5750 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5751 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5752 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5753 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5754 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5755 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5756 | }; |
| 5757 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5758 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5759 | arraysize(spdy_writes)); |
| 5760 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5761 | |
| 5762 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5763 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5765 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5766 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5767 | |
| 5768 | TestCompletionCallback callback; |
| 5769 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5770 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5771 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5772 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5773 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5774 | |
| 5775 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5776 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5777 | |
| 5778 | LoadTimingInfo load_timing_info; |
| 5779 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5780 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5781 | |
| 5782 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5783 | ASSERT_TRUE(response); |
| 5784 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5785 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5786 | |
| 5787 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5788 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5789 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5790 | trans.reset(); |
| 5791 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5792 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5793 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5794 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5795 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5796 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5797 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5798 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5799 | |
| 5800 | LoadTimingInfo load_timing_info2; |
| 5801 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5802 | TestLoadTimingReused(load_timing_info2); |
| 5803 | |
| 5804 | // The requests should have the same ID. |
| 5805 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5806 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5807 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5811 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5812 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5813 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5814 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5815 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5816 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5817 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5818 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5819 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5820 | |
| 5821 | HttpRequestInfo request1; |
| 5822 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5823 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5824 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5825 | request1.traffic_annotation = |
| 5826 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5827 | |
| 5828 | HttpRequestInfo request2; |
| 5829 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5830 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5831 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5832 | request2.traffic_annotation = |
| 5833 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5834 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5835 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5836 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5837 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5838 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5839 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5840 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5841 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5842 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5843 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5844 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5845 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5846 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5847 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5848 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5849 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5850 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5851 | |
| 5852 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5853 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5854 | }; |
| 5855 | |
| 5856 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5857 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5858 | CreateMockRead(body1, 2, ASYNC), |
| 5859 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5860 | CreateMockRead(body2, 5, ASYNC), |
| 5861 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5862 | }; |
| 5863 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5864 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5865 | arraysize(spdy_writes)); |
| 5866 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5867 | |
| 5868 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5869 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5870 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5871 | |
| 5872 | TestCompletionCallback callback; |
| 5873 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5874 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5875 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5876 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5877 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5878 | |
| 5879 | LoadTimingInfo load_timing_info; |
| 5880 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5881 | TestLoadTimingNotReused(load_timing_info, |
| 5882 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5883 | |
| 5884 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5885 | ASSERT_TRUE(response); |
| 5886 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5887 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5888 | |
| 5889 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5890 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5891 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5892 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5893 | // Delete the first request, so the second one can reuse the socket. |
| 5894 | trans.reset(); |
| 5895 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5896 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5897 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5898 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5899 | |
| 5900 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5901 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5902 | TestLoadTimingReused(load_timing_info2); |
| 5903 | |
| 5904 | // The requests should have the same ID. |
| 5905 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5906 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5907 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5908 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5909 | } |
| 5910 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5911 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5912 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5913 | HttpRequestInfo request; |
| 5914 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5915 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5916 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5917 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5918 | request.traffic_annotation = |
| 5919 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5920 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5921 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5922 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5923 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5924 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5925 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5926 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5927 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5928 | // Since we have proxy, should use full url |
| 5929 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5930 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5931 | "Host: www.example.org\r\n" |
| 5932 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5933 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5934 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5935 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5936 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5937 | "Host: www.example.org\r\n" |
| 5938 | "Proxy-Connection: keep-alive\r\n" |
| 5939 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5940 | }; |
| 5941 | |
| 5942 | // The proxy responds to the GET with a 407, using a persistent |
| 5943 | // connection. |
| 5944 | MockRead data_reads1[] = { |
| 5945 | // No credentials. |
| 5946 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5947 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5948 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5949 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5950 | |
| 5951 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5952 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5953 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5954 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5955 | }; |
| 5956 | |
| 5957 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5958 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5959 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5960 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5961 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5962 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5963 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5964 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5965 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5966 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5967 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5968 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5969 | |
| 5970 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5971 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5972 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5973 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5974 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5975 | TestLoadTimingNotReused(load_timing_info, |
| 5976 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5977 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5978 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5979 | ASSERT_TRUE(response); |
| 5980 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5981 | EXPECT_EQ(407, response->headers->response_code()); |
| 5982 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5983 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5984 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5985 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5986 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5987 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5988 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5989 | |
| 5990 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5991 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5992 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5993 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5994 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5995 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5996 | TestLoadTimingReused(load_timing_info); |
| 5997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5998 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5999 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6000 | |
| 6001 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6002 | EXPECT_EQ(200, response->headers->response_code()); |
| 6003 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6004 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6005 | |
| 6006 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6007 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6008 | } |
| 6009 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6010 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6011 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6012 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6013 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6014 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6015 | request.traffic_annotation = |
| 6016 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6017 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6018 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6019 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6020 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6021 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6022 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6023 | // Since we have proxy, should try to establish tunnel. |
| 6024 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6025 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6026 | "Host: www.example.org:443\r\n" |
| 6027 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6028 | }; |
| 6029 | |
| 6030 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6031 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6032 | // No response body because the test stops reading here. |
| 6033 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6034 | }; |
| 6035 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6036 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6037 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6038 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6040 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6041 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6042 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6043 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6044 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6045 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6046 | |
| 6047 | rv = callback.WaitForResult(); |
| 6048 | EXPECT_EQ(expected_status, rv); |
| 6049 | } |
| 6050 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6051 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6052 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6053 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6054 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6055 | } |
| 6056 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6057 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6058 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6059 | } |
| 6060 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6061 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6062 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6063 | } |
| 6064 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6065 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6066 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6067 | } |
| 6068 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6069 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6070 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6071 | } |
| 6072 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6073 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6074 | ConnectStatusHelper( |
| 6075 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6076 | } |
| 6077 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6078 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6079 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6080 | } |
| 6081 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6082 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6083 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6084 | } |
| 6085 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6086 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6087 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6088 | } |
| 6089 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6090 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6091 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6092 | } |
| 6093 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6094 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6095 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6096 | } |
| 6097 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6098 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6099 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6100 | } |
| 6101 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6102 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6103 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6104 | } |
| 6105 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6106 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6107 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6108 | } |
| 6109 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6110 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6111 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6112 | } |
| 6113 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6114 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6115 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6116 | } |
| 6117 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6118 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6119 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6120 | } |
| 6121 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6122 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6123 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6124 | } |
| 6125 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6126 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6127 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6128 | } |
| 6129 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6130 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6131 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6132 | } |
| 6133 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6134 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6135 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6136 | } |
| 6137 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6138 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6139 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6140 | } |
| 6141 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6142 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6143 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6144 | } |
| 6145 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6146 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6147 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6148 | } |
| 6149 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6150 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6151 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6152 | } |
| 6153 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6154 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6155 | ConnectStatusHelperWithExpectedStatus( |
| 6156 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6157 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6158 | } |
| 6159 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6160 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6161 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6162 | } |
| 6163 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6164 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6165 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6166 | } |
| 6167 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6168 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6169 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6170 | } |
| 6171 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6172 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6173 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6174 | } |
| 6175 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6176 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6177 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6178 | } |
| 6179 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6180 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6181 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6182 | } |
| 6183 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6184 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6185 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6186 | } |
| 6187 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6188 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6189 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6190 | } |
| 6191 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6192 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6193 | ConnectStatusHelper( |
| 6194 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6195 | } |
| 6196 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6197 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6198 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6199 | } |
| 6200 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6201 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6202 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6203 | } |
| 6204 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6205 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6206 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6207 | } |
| 6208 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6209 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6210 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6211 | } |
| 6212 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6213 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6214 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6215 | } |
| 6216 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6217 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6218 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6219 | } |
| 6220 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6221 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6222 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6223 | } |
| 6224 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6225 | // Test the flow when both the proxy server AND origin server require |
| 6226 | // authentication. Again, this uses basic auth for both since that is |
| 6227 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6228 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6229 | HttpRequestInfo request; |
| 6230 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6231 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6232 | request.traffic_annotation = |
| 6233 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6234 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6235 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6236 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6237 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6238 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6240 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6241 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6242 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6243 | MockWrite( |
| 6244 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6245 | "Host: www.example.org\r\n" |
| 6246 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6247 | }; |
| 6248 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6249 | MockRead data_reads1[] = { |
| 6250 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6251 | // Give a couple authenticate options (only the middle one is actually |
| 6252 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6253 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6254 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6255 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6256 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6257 | // Large content-length -- won't matter, as connection will be reset. |
| 6258 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6259 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6260 | }; |
| 6261 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6262 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6263 | // request we should be issuing -- the final header line contains the |
| 6264 | // proxy's credentials. |
| 6265 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6266 | MockWrite( |
| 6267 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6268 | "Host: www.example.org\r\n" |
| 6269 | "Proxy-Connection: keep-alive\r\n" |
| 6270 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6271 | }; |
| 6272 | |
| 6273 | // Now the proxy server lets the request pass through to origin server. |
| 6274 | // The origin server responds with a 401. |
| 6275 | MockRead data_reads2[] = { |
| 6276 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6277 | // Note: We are using the same realm-name as the proxy server. This is |
| 6278 | // completely valid, as realms are unique across hosts. |
| 6279 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6280 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6281 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6282 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6283 | }; |
| 6284 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6285 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6286 | // the credentials for both the proxy and origin server. |
| 6287 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6288 | MockWrite( |
| 6289 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6290 | "Host: www.example.org\r\n" |
| 6291 | "Proxy-Connection: keep-alive\r\n" |
| 6292 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 6293 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6294 | }; |
| 6295 | |
| 6296 | // Lastly we get the desired content. |
| 6297 | MockRead data_reads3[] = { |
| 6298 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6299 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6300 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6301 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6302 | }; |
| 6303 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6304 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6305 | data_writes1, arraysize(data_writes1)); |
| 6306 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6307 | data_writes2, arraysize(data_writes2)); |
| 6308 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6309 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6310 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6311 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6312 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6313 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6314 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6315 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6316 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6317 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6318 | |
| 6319 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6320 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6321 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6322 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6323 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6324 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6325 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6326 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6327 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6328 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6329 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6330 | |
| 6331 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6332 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6333 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6334 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6335 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6336 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6337 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6338 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6339 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6340 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 6341 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6342 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6343 | |
| 6344 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6345 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6346 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6347 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6348 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6349 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6350 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6351 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6352 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 6353 | // can't hook into its internals to cause it to generate predictable NTLM |
| 6354 | // authorization headers. |
| 6355 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6356 | // The NTLM authentication unit tests are based on known test data from the |
| 6357 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 6358 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 6359 | // for the implementation and testing of the protocol. |
| 6360 | // |
| 6361 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6362 | |
| 6363 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6364 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6365 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6366 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6367 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6368 | request.traffic_annotation = |
| 6369 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6370 | |
| 6371 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6372 | // to other auth schemes. |
| 6373 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6374 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6375 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6376 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6377 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6378 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6379 | // Generate the NTLM messages based on known test data. |
| 6380 | std::string negotiate_msg; |
| 6381 | std::string challenge_msg; |
| 6382 | std::string authenticate_msg; |
| 6383 | base::Base64Encode( |
| 6384 | base::StringPiece( |
| 6385 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6386 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6387 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6388 | base::Base64Encode( |
| 6389 | base::StringPiece( |
| 6390 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6391 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6392 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6393 | base::Base64Encode( |
| 6394 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6395 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6396 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6397 | arraysize( |
| 6398 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6399 | &authenticate_msg); |
| 6400 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6401 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6402 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6403 | "Host: server\r\n" |
| 6404 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6405 | }; |
| 6406 | |
| 6407 | MockRead data_reads1[] = { |
| 6408 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6409 | // Negotiate and NTLM are often requested together. However, we only want |
| 6410 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6411 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6412 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6413 | MockRead("Connection: close\r\n"), |
| 6414 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6415 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6416 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6417 | }; |
| 6418 | |
| 6419 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6420 | // After restarting with a null identity, this is the |
| 6421 | // request we should be issuing -- the final header line contains a Type |
| 6422 | // 1 message. |
| 6423 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6424 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6425 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6426 | "Authorization: NTLM "), |
| 6427 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6428 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6429 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6430 | // (using correct credentials). The second request continues on the |
| 6431 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6432 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6433 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6434 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6435 | "Authorization: NTLM "), |
| 6436 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6437 | }; |
| 6438 | |
| 6439 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6440 | // The origin server responds with a Type 2 message. |
| 6441 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6442 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6443 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6444 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6445 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6446 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6447 | // Lastly we get the desired content. |
| 6448 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6449 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6450 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6451 | }; |
| 6452 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6453 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6454 | data_writes1, arraysize(data_writes1)); |
| 6455 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6456 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6457 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6458 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6459 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6460 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6461 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6462 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6463 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6464 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6465 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6466 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6467 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6468 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6469 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6471 | |
| 6472 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6473 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6475 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6477 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6478 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6479 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6480 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6481 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6482 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6483 | rv = trans.RestartWithAuth( |
| 6484 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6485 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6487 | |
| 6488 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6489 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6490 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6491 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6492 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6493 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6494 | ASSERT_TRUE(response); |
| 6495 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6497 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6499 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6500 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6501 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6502 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6503 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6504 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6505 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6506 | ASSERT_TRUE(response); |
| 6507 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6508 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6509 | |
| 6510 | std::string response_data; |
| 6511 | rv = ReadTransaction(&trans, &response_data); |
| 6512 | EXPECT_THAT(rv, IsOk()); |
| 6513 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6514 | |
| 6515 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6516 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6517 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6518 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6519 | } |
| 6520 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6521 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6522 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6523 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6524 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6525 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6526 | request.traffic_annotation = |
| 6527 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6528 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6529 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6530 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6531 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6532 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6533 | // Generate the NTLM messages based on known test data. |
| 6534 | std::string negotiate_msg; |
| 6535 | std::string challenge_msg; |
| 6536 | std::string authenticate_msg; |
| 6537 | base::Base64Encode( |
| 6538 | base::StringPiece( |
| 6539 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6540 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6541 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6542 | base::Base64Encode( |
| 6543 | base::StringPiece( |
| 6544 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6545 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6546 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6547 | base::Base64Encode( |
| 6548 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6549 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6550 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6551 | arraysize( |
| 6552 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6553 | &authenticate_msg); |
| 6554 | |
| 6555 | // The authenticate message when |kWrongPassword| is sent. |
| 6556 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6557 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 6558 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 6559 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 6560 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 6561 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 6562 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6563 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6564 | // Sanity check that it's the same length as the correct authenticate message |
| 6565 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6566 | ASSERT_EQ(authenticate_msg.length(), |
| 6567 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6568 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6569 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6570 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6571 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6572 | "Host: server\r\n" |
| 6573 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6574 | }; |
| 6575 | |
| 6576 | MockRead data_reads1[] = { |
| 6577 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6578 | // Negotiate and NTLM are often requested together. However, we only want |
| 6579 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6580 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6581 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6582 | MockRead("Connection: close\r\n"), |
| 6583 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6584 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6585 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6586 | }; |
| 6587 | |
| 6588 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6589 | // After restarting with a null identity, this is the |
| 6590 | // request we should be issuing -- the final header line contains a Type |
| 6591 | // 1 message. |
| 6592 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6593 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6594 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6595 | "Authorization: NTLM "), |
| 6596 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6597 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6598 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6599 | // (using incorrect credentials). The second request continues on the |
| 6600 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6601 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6602 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6603 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6604 | "Authorization: NTLM "), |
| 6605 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6606 | }; |
| 6607 | |
| 6608 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6609 | // The origin server responds with a Type 2 message. |
| 6610 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6611 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6612 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 6613 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6614 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6615 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6616 | // Wrong password. |
| 6617 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6618 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 6619 | MockRead("Content-Length: 42\r\n"), |
| 6620 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6621 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6622 | }; |
| 6623 | |
| 6624 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6625 | // After restarting with a null identity, this is the |
| 6626 | // request we should be issuing -- the final header line contains a Type |
| 6627 | // 1 message. |
| 6628 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6629 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6630 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6631 | "Authorization: NTLM "), |
| 6632 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6634 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6635 | // (the credentials for the origin server). The second request continues |
| 6636 | // on the same connection. |
| 6637 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6638 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6639 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6640 | "Authorization: NTLM "), |
| 6641 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6642 | }; |
| 6643 | |
| 6644 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6645 | // The origin server responds with a Type 2 message. |
| 6646 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6647 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6648 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6649 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6650 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6651 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6652 | // Lastly we get the desired content. |
| 6653 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6654 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6655 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6656 | }; |
| 6657 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6658 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6659 | data_writes1, arraysize(data_writes1)); |
| 6660 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6661 | data_writes2, arraysize(data_writes2)); |
| 6662 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6663 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6664 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6665 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6666 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6667 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6668 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6669 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6670 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6671 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6672 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6673 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6674 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6675 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6676 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6677 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6678 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6679 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6681 | |
| 6682 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6683 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6685 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6686 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6687 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6688 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6689 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6690 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6691 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6692 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6693 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6694 | rv = trans.RestartWithAuth( |
| 6695 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 6696 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6697 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6698 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6699 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6700 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6701 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6702 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6703 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6704 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6705 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6706 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6707 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6708 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6709 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6710 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6711 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6712 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6713 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6714 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6715 | |
| 6716 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6717 | rv = trans.RestartWithAuth( |
| 6718 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6719 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6720 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6721 | |
| 6722 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6723 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6724 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6725 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6727 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6728 | |
| 6729 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6730 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6731 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6732 | |
| 6733 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6734 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6735 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6736 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6737 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6738 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6739 | |
| 6740 | std::string response_data; |
| 6741 | rv = ReadTransaction(&trans, &response_data); |
| 6742 | EXPECT_THAT(rv, IsOk()); |
| 6743 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6744 | |
| 6745 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6746 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6747 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6748 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6749 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6750 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6751 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6752 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6753 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 6754 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6755 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6756 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6757 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6758 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6759 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6760 | |
| 6761 | HttpRequestInfo request; |
| 6762 | request.method = "GET"; |
| 6763 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6764 | request.traffic_annotation = |
| 6765 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6766 | |
| 6767 | // First request without credentials. |
| 6768 | SpdyHeaderBlock request_headers0(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6769 | SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
| 6770 | 1, std::move(request_headers0), LOWEST, true)); |
| 6771 | |
| 6772 | SpdyHeaderBlock response_headers0; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 6773 | response_headers0[kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6774 | response_headers0["www-authenticate"] = "NTLM"; |
| 6775 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
| 6776 | 1, std::move(response_headers0), true)); |
| 6777 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6778 | // Stream 1 is closed. |
| 6779 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6780 | |
| 6781 | // Generate the NTLM messages based on known test data. |
| 6782 | std::string negotiate_msg; |
| 6783 | std::string challenge_msg; |
| 6784 | std::string authenticate_msg; |
| 6785 | base::Base64Encode( |
| 6786 | base::StringPiece( |
| 6787 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6788 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6789 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6790 | base::Base64Encode( |
| 6791 | base::StringPiece( |
| 6792 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6793 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6794 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6795 | base::Base64Encode( |
| 6796 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6797 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6798 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6799 | arraysize( |
| 6800 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6801 | &authenticate_msg); |
| 6802 | |
| 6803 | // Retry with authorization header. |
| 6804 | SpdyHeaderBlock request_headers1(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6805 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
| 6806 | SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
| 6807 | 3, std::move(request_headers1), LOWEST, true)); |
| 6808 | |
| 6809 | SpdySerializedFrame rst( |
| 6810 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_HTTP_1_1_REQUIRED)); |
| 6811 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6812 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 6813 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6814 | |
| 6815 | // Retry yet again using HTTP/1.1. |
| 6816 | MockWrite writes1[] = { |
| 6817 | // After restarting with a null identity, this is the |
| 6818 | // request we should be issuing -- the final header line contains a Type |
| 6819 | // 1 message. |
| 6820 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6821 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6822 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6823 | "Authorization: NTLM "), |
| 6824 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6825 | |
| 6826 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6827 | // (the credentials for the origin server). The second request continues |
| 6828 | // on the same connection. |
| 6829 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6830 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6831 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6832 | "Authorization: NTLM "), |
| 6833 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6834 | }; |
| 6835 | |
| 6836 | MockRead reads1[] = { |
| 6837 | // The origin server responds with a Type 2 message. |
| 6838 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6839 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6840 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6841 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6842 | MockRead("You are not authorized to view this page\r\n"), |
| 6843 | |
| 6844 | // Lastly we get the desired content. |
| 6845 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6846 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6847 | 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] | 6848 | }; |
| 6849 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 6850 | arraysize(writes0)); |
| 6851 | StaticSocketDataProvider data1(reads1, arraysize(reads1), writes1, |
| 6852 | arraysize(writes1)); |
| 6853 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6854 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6855 | |
| 6856 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6857 | ssl0.next_proto = kProtoHTTP2; |
| 6858 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6859 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6860 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6861 | |
| 6862 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6863 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6864 | |
| 6865 | TestCompletionCallback callback1; |
| 6866 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6867 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6868 | |
| 6869 | rv = callback1.WaitForResult(); |
| 6870 | EXPECT_THAT(rv, IsOk()); |
| 6871 | |
| 6872 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6873 | |
| 6874 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6875 | ASSERT_TRUE(response); |
| 6876 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6877 | |
| 6878 | TestCompletionCallback callback2; |
| 6879 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6880 | rv = trans.RestartWithAuth( |
| 6881 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6882 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6883 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6884 | |
| 6885 | rv = callback2.WaitForResult(); |
| 6886 | EXPECT_THAT(rv, IsOk()); |
| 6887 | |
| 6888 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6889 | |
| 6890 | response = trans.GetResponseInfo(); |
| 6891 | ASSERT_TRUE(response); |
| 6892 | EXPECT_FALSE(response->auth_challenge); |
| 6893 | |
| 6894 | TestCompletionCallback callback3; |
| 6895 | |
| 6896 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6898 | |
| 6899 | rv = callback3.WaitForResult(); |
| 6900 | EXPECT_THAT(rv, IsOk()); |
| 6901 | |
| 6902 | response = trans.GetResponseInfo(); |
| 6903 | ASSERT_TRUE(response); |
| 6904 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6905 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6906 | |
| 6907 | std::string response_data; |
| 6908 | rv = ReadTransaction(&trans, &response_data); |
| 6909 | EXPECT_THAT(rv, IsOk()); |
| 6910 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6911 | |
| 6912 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6913 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6914 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6915 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6916 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6917 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6918 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6919 | // Test reading a server response which has only headers, and no body. |
| 6920 | // After some maximum number of bytes is consumed, the transaction should |
| 6921 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6922 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6923 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6924 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6925 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6926 | request.traffic_annotation = |
| 6927 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6928 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6929 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6930 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6931 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6932 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6933 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6934 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6935 | |
| 6936 | MockRead data_reads[] = { |
| 6937 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6938 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6939 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6940 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6941 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6942 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6943 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6944 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6945 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6946 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6947 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6948 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6949 | |
| 6950 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6951 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6952 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6953 | |
| 6954 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6955 | // establish tunnel. |
| 6956 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6957 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6958 | HttpRequestInfo request; |
| 6959 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6960 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6961 | request.traffic_annotation = |
| 6962 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6963 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6964 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6965 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6966 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6967 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6969 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6970 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6971 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6972 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6973 | // Since we have proxy, should try to establish tunnel. |
| 6974 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6975 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6976 | "Host: www.example.org:443\r\n" |
| 6977 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6978 | }; |
| 6979 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6980 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6981 | // connection. Usually a proxy would return 501 (not implemented), |
| 6982 | // or 200 (tunnel established). |
| 6983 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6984 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6985 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6986 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6987 | }; |
| 6988 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6989 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6990 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6991 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6993 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6994 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6995 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6996 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6997 | |
| 6998 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6999 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7000 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7001 | // Empty the current queue. This is necessary because idle sockets are |
| 7002 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7003 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7004 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7005 | // We now check to make sure the TCPClientSocket was not added back to |
| 7006 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7007 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7008 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7009 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7010 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7011 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7012 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7013 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7014 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7015 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7016 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7017 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7018 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7019 | request.traffic_annotation = |
| 7020 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7021 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7022 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7023 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7024 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7025 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7026 | MockRead data_reads[] = { |
| 7027 | // A part of the response body is received with the response headers. |
| 7028 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7029 | // The rest of the response body is received in two parts. |
| 7030 | MockRead("lo"), |
| 7031 | MockRead(" world"), |
| 7032 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7033 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7034 | }; |
| 7035 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7036 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7037 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7038 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7039 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7040 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7041 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7042 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7043 | |
| 7044 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7045 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7046 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7047 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7048 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7049 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7050 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7051 | std::string status_line = response->headers->GetStatusLine(); |
| 7052 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7053 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7054 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7055 | |
| 7056 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7057 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7058 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7059 | EXPECT_EQ("hello world", response_data); |
| 7060 | |
| 7061 | // Empty the current queue. This is necessary because idle sockets are |
| 7062 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7063 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7064 | |
| 7065 | // 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] | 7066 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7067 | } |
| 7068 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7069 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7070 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7071 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7072 | HttpRequestInfo request; |
| 7073 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7074 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7075 | request.traffic_annotation = |
| 7076 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7077 | |
| 7078 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7079 | MockWrite( |
| 7080 | "GET / HTTP/1.1\r\n" |
| 7081 | "Host: www.example.org\r\n" |
| 7082 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7083 | }; |
| 7084 | |
| 7085 | MockRead data_reads[] = { |
| 7086 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7087 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7088 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7089 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7090 | }; |
| 7091 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7092 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7093 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7094 | |
| 7095 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7096 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7097 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7098 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7099 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7100 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7101 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7102 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7103 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7104 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7105 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7106 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7107 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7108 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7109 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7110 | ASSERT_TRUE(response); |
| 7111 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7112 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7113 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7114 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7115 | |
| 7116 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7117 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7118 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7119 | EXPECT_EQ("hello world", response_data); |
| 7120 | |
| 7121 | // Empty the current queue. This is necessary because idle sockets are |
| 7122 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7123 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7124 | |
| 7125 | // 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] | 7126 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7127 | } |
| 7128 | |
| 7129 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 7130 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7131 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7132 | HttpRequestInfo request; |
| 7133 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7134 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7135 | request.traffic_annotation = |
| 7136 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7137 | |
| 7138 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7139 | MockWrite( |
| 7140 | "GET / HTTP/1.1\r\n" |
| 7141 | "Host: www.example.org\r\n" |
| 7142 | "Connection: keep-alive\r\n\r\n"), |
| 7143 | MockWrite( |
| 7144 | "GET / HTTP/1.1\r\n" |
| 7145 | "Host: www.example.org\r\n" |
| 7146 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7147 | }; |
| 7148 | |
| 7149 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 7150 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7151 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7152 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7153 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7154 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7155 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7156 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7157 | |
| 7158 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7159 | data_writes, arraysize(data_writes)); |
| 7160 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 7161 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7162 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7163 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7165 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7166 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7167 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7168 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7169 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7170 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7171 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7172 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7173 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7174 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7175 | |
| 7176 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7177 | ASSERT_TRUE(response); |
| 7178 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7179 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7180 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7181 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7182 | |
| 7183 | std::string response_data; |
| 7184 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7185 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7186 | EXPECT_EQ("hello world", response_data); |
| 7187 | |
| 7188 | // Empty the current queue. This is necessary because idle sockets are |
| 7189 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7190 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7191 | |
| 7192 | // 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] | 7193 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7194 | |
| 7195 | // Now start the second transaction, which should reuse the previous socket. |
| 7196 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7197 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7198 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7199 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7200 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7201 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7202 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7203 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7204 | |
| 7205 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7206 | ASSERT_TRUE(response); |
| 7207 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7208 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7209 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7210 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7211 | |
| 7212 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7213 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7214 | EXPECT_EQ("hello world", response_data); |
| 7215 | |
| 7216 | // Empty the current queue. This is necessary because idle sockets are |
| 7217 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7218 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7219 | |
| 7220 | // 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] | 7221 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7222 | } |
| 7223 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7224 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7225 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7226 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7227 | HttpRequestInfo request; |
| 7228 | request.method = "GET"; |
| 7229 | request.url = GURL("http://www.example.org/"); |
| 7230 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7231 | request.traffic_annotation = |
| 7232 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7233 | |
| 7234 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7235 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7236 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7237 | |
| 7238 | MockRead data_reads[] = { |
| 7239 | // A part of the response body is received with the response headers. |
| 7240 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7241 | // The rest of the response body is received in two parts. |
| 7242 | MockRead("lo"), MockRead(" world"), |
| 7243 | MockRead("junk"), // Should not be read!! |
| 7244 | MockRead(SYNCHRONOUS, OK), |
| 7245 | }; |
| 7246 | |
| 7247 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7248 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7249 | |
| 7250 | TestCompletionCallback callback; |
| 7251 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7252 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7253 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7254 | |
| 7255 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7256 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7257 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7258 | ASSERT_TRUE(response); |
| 7259 | EXPECT_TRUE(response->headers); |
| 7260 | std::string status_line = response->headers->GetStatusLine(); |
| 7261 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7262 | |
| 7263 | // Make memory critical notification and ensure the transaction still has been |
| 7264 | // operating right. |
| 7265 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7266 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7267 | base::RunLoop().RunUntilIdle(); |
| 7268 | |
| 7269 | // Socket should not be flushed as long as it is not idle. |
| 7270 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7271 | |
| 7272 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7273 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7274 | EXPECT_THAT(rv, IsOk()); |
| 7275 | EXPECT_EQ("hello world", response_data); |
| 7276 | |
| 7277 | // Empty the current queue. This is necessary because idle sockets are |
| 7278 | // added to the connection pool asynchronously with a PostTask. |
| 7279 | base::RunLoop().RunUntilIdle(); |
| 7280 | |
| 7281 | // We now check to make sure the socket was added back to the pool. |
| 7282 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7283 | |
| 7284 | // Idle sockets should be flushed now. |
| 7285 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7286 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7287 | base::RunLoop().RunUntilIdle(); |
| 7288 | |
| 7289 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7290 | } |
| 7291 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7292 | // Disable idle socket closing on memory pressure. |
| 7293 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7294 | // low memory notification and ensure the socket pool is NOT flushed. |
| 7295 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 7296 | HttpRequestInfo request; |
| 7297 | request.method = "GET"; |
| 7298 | request.url = GURL("http://www.example.org/"); |
| 7299 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7300 | request.traffic_annotation = |
| 7301 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7302 | |
| 7303 | // Disable idle socket closing on memory pressure. |
| 7304 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 7305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7306 | |
| 7307 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 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 | |
| 7323 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 7324 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7325 | |
| 7326 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7327 | |
| 7328 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 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; |
| 7344 | rv = ReadTransaction(&trans, &response_data); |
| 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 NOT be flushed on moderate memory pressure. |
| 7356 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7357 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 7358 | base::RunLoop().RunUntilIdle(); |
| 7359 | |
| 7360 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7361 | |
| 7362 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 7363 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7364 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7365 | base::RunLoop().RunUntilIdle(); |
| 7366 | |
| 7367 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7368 | } |
| 7369 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7370 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 7371 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7372 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7373 | HttpRequestInfo request; |
| 7374 | request.method = "GET"; |
| 7375 | request.url = GURL("https://www.example.org/"); |
| 7376 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7377 | request.traffic_annotation = |
| 7378 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7379 | |
| 7380 | MockWrite data_writes[] = { |
| 7381 | MockWrite("GET / HTTP/1.1\r\n" |
| 7382 | "Host: www.example.org\r\n" |
| 7383 | "Connection: keep-alive\r\n\r\n"), |
| 7384 | }; |
| 7385 | |
| 7386 | MockRead data_reads[] = { |
| 7387 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7388 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 7389 | |
| 7390 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7391 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7392 | |
| 7393 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 7394 | arraysize(data_writes)); |
| 7395 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7396 | |
| 7397 | TestCompletionCallback callback; |
| 7398 | |
| 7399 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7400 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7401 | |
| 7402 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7403 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7404 | |
| 7405 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7407 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7408 | ASSERT_TRUE(response); |
| 7409 | ASSERT_TRUE(response->headers); |
| 7410 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7411 | |
| 7412 | // Make memory critical notification and ensure the transaction still has been |
| 7413 | // operating right. |
| 7414 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7415 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7416 | base::RunLoop().RunUntilIdle(); |
| 7417 | |
| 7418 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7419 | |
| 7420 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7421 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7422 | EXPECT_THAT(rv, IsOk()); |
| 7423 | EXPECT_EQ("hello world", response_data); |
| 7424 | |
| 7425 | // Empty the current queue. This is necessary because idle sockets are |
| 7426 | // added to the connection pool asynchronously with a PostTask. |
| 7427 | base::RunLoop().RunUntilIdle(); |
| 7428 | |
| 7429 | // We now check to make sure the socket was added back to the pool. |
| 7430 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7431 | |
| 7432 | // Make memory notification once again and ensure idle socket is closed. |
| 7433 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7434 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7435 | base::RunLoop().RunUntilIdle(); |
| 7436 | |
| 7437 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7438 | } |
| 7439 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7440 | // Make sure that we recycle a socket after a zero-length response. |
| 7441 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7442 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7443 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7444 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7445 | request.url = GURL( |
| 7446 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 7447 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 7448 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 7449 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7450 | request.traffic_annotation = |
| 7451 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7452 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7453 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7454 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7455 | MockRead data_reads[] = { |
| 7456 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 7457 | "Content-Length: 0\r\n" |
| 7458 | "Content-Type: text/html\r\n\r\n"), |
| 7459 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7460 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7461 | }; |
| 7462 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7463 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7464 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7465 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7466 | // Transaction must be created after the MockReads, so it's destroyed before |
| 7467 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7468 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7470 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7471 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7472 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7473 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7474 | |
| 7475 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7476 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7479 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7480 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7481 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7482 | std::string status_line = response->headers->GetStatusLine(); |
| 7483 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 7484 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7485 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7486 | |
| 7487 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7488 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7489 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7490 | EXPECT_EQ("", response_data); |
| 7491 | |
| 7492 | // Empty the current queue. This is necessary because idle sockets are |
| 7493 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7494 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7495 | |
| 7496 | // 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] | 7497 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7498 | } |
| 7499 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7500 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7501 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7502 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7503 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7504 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7505 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7506 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7507 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 7508 | // after use. |
| 7509 | request[0].method = "GET"; |
| 7510 | request[0].url = GURL("http://www.google.com/"); |
| 7511 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7512 | request[0].traffic_annotation = |
| 7513 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7514 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 7515 | // transaction 1. The first attempts fails when writing the POST data. |
| 7516 | // This causes the transaction to retry with a new socket. The second |
| 7517 | // attempt succeeds. |
| 7518 | request[1].method = "POST"; |
| 7519 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7520 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7521 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7522 | request[1].traffic_annotation = |
| 7523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7524 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7525 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7526 | |
| 7527 | // The first socket is used for transaction 1 and the first attempt of |
| 7528 | // transaction 2. |
| 7529 | |
| 7530 | // The response of transaction 1. |
| 7531 | MockRead data_reads1[] = { |
| 7532 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 7533 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7534 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7535 | }; |
| 7536 | // The mock write results of transaction 1 and the first attempt of |
| 7537 | // transaction 2. |
| 7538 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7539 | MockWrite(SYNCHRONOUS, 64), // GET |
| 7540 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7541 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7542 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7543 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7544 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7545 | |
| 7546 | // The second socket is used for the second attempt of transaction 2. |
| 7547 | |
| 7548 | // The response of transaction 2. |
| 7549 | MockRead data_reads2[] = { |
| 7550 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 7551 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7552 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7553 | }; |
| 7554 | // The mock write results of the second attempt of transaction 2. |
| 7555 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7556 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7557 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7558 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7559 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7560 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7561 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7562 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7563 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7564 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7565 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7566 | "hello world", "welcome" |
| 7567 | }; |
| 7568 | |
| 7569 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7570 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7571 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7572 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7573 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7574 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7575 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7576 | |
| 7577 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7578 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7579 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7580 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7581 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7582 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7583 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7584 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7585 | |
| 7586 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7587 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7588 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7589 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7590 | } |
| 7591 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7592 | |
| 7593 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7594 | // 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] | 7595 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7596 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7597 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7598 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7599 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7600 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7601 | request.traffic_annotation = |
| 7602 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7603 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7604 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7605 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7606 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7607 | // The password contains an escaped character -- for this test to pass it |
| 7608 | // will need to be unescaped by HttpNetworkTransaction. |
| 7609 | EXPECT_EQ("b%40r", request.url.password()); |
| 7610 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7611 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7612 | MockWrite( |
| 7613 | "GET / HTTP/1.1\r\n" |
| 7614 | "Host: www.example.org\r\n" |
| 7615 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7616 | }; |
| 7617 | |
| 7618 | MockRead data_reads1[] = { |
| 7619 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7620 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7621 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7622 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7623 | }; |
| 7624 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7625 | // After the challenge above, the transaction will be restarted using the |
| 7626 | // identity from the url (foo, b@r) to answer the challenge. |
| 7627 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7628 | MockWrite( |
| 7629 | "GET / HTTP/1.1\r\n" |
| 7630 | "Host: www.example.org\r\n" |
| 7631 | "Connection: keep-alive\r\n" |
| 7632 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7633 | }; |
| 7634 | |
| 7635 | MockRead data_reads2[] = { |
| 7636 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7637 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7638 | MockRead(SYNCHRONOUS, OK), |
| 7639 | }; |
| 7640 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7641 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7642 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7643 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7644 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7645 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7646 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7648 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7649 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7650 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7651 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7652 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7653 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7654 | |
| 7655 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7656 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7657 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7658 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7659 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7660 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7661 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7662 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7663 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7664 | |
| 7665 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7666 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7667 | |
| 7668 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7669 | |
| 7670 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7671 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7672 | } |
| 7673 | |
| 7674 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7675 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7676 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7677 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7678 | HttpRequestInfo request; |
| 7679 | request.method = "GET"; |
| 7680 | // Note: the URL has a username:password in it. The password "baz" is |
| 7681 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7682 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7683 | |
| 7684 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7685 | request.traffic_annotation = |
| 7686 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7687 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7689 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7690 | |
| 7691 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7692 | MockWrite( |
| 7693 | "GET / HTTP/1.1\r\n" |
| 7694 | "Host: www.example.org\r\n" |
| 7695 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7696 | }; |
| 7697 | |
| 7698 | MockRead data_reads1[] = { |
| 7699 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7700 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7701 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7702 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7703 | }; |
| 7704 | |
| 7705 | // After the challenge above, the transaction will be restarted using the |
| 7706 | // identity from the url (foo, baz) to answer the challenge. |
| 7707 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7708 | MockWrite( |
| 7709 | "GET / HTTP/1.1\r\n" |
| 7710 | "Host: www.example.org\r\n" |
| 7711 | "Connection: keep-alive\r\n" |
| 7712 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7713 | }; |
| 7714 | |
| 7715 | MockRead data_reads2[] = { |
| 7716 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7717 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7718 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7719 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7720 | }; |
| 7721 | |
| 7722 | // After the challenge above, the transaction will be restarted using the |
| 7723 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7724 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7725 | MockWrite( |
| 7726 | "GET / HTTP/1.1\r\n" |
| 7727 | "Host: www.example.org\r\n" |
| 7728 | "Connection: keep-alive\r\n" |
| 7729 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7730 | }; |
| 7731 | |
| 7732 | MockRead data_reads3[] = { |
| 7733 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7734 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7735 | MockRead(SYNCHRONOUS, OK), |
| 7736 | }; |
| 7737 | |
| 7738 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7739 | data_writes1, arraysize(data_writes1)); |
| 7740 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7741 | data_writes2, arraysize(data_writes2)); |
| 7742 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7743 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7744 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7745 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7746 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7747 | |
| 7748 | TestCompletionCallback callback1; |
| 7749 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7750 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7751 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7752 | |
| 7753 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7754 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7755 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7756 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7757 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7758 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7759 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7760 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7761 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7762 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7763 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7764 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7765 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7766 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7767 | |
| 7768 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7769 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7770 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7771 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7772 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7773 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7774 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7775 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7776 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7777 | |
| 7778 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7779 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7780 | |
| 7781 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7782 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7783 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7784 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7785 | } |
| 7786 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7787 | |
| 7788 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7789 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7790 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7791 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7792 | HttpRequestInfo request; |
| 7793 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7794 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7795 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7796 | request.traffic_annotation = |
| 7797 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7798 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7799 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7800 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7801 | |
| 7802 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7803 | MockWrite( |
| 7804 | "GET / HTTP/1.1\r\n" |
| 7805 | "Host: www.example.org\r\n" |
| 7806 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7807 | }; |
| 7808 | |
| 7809 | MockRead data_reads1[] = { |
| 7810 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7811 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7812 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7813 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7814 | }; |
| 7815 | |
| 7816 | // After the challenge above, the transaction will be restarted using the |
| 7817 | // identity supplied by the user, not the one in the URL, to answer the |
| 7818 | // challenge. |
| 7819 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7820 | MockWrite( |
| 7821 | "GET / HTTP/1.1\r\n" |
| 7822 | "Host: www.example.org\r\n" |
| 7823 | "Connection: keep-alive\r\n" |
| 7824 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7825 | }; |
| 7826 | |
| 7827 | MockRead data_reads3[] = { |
| 7828 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7829 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7830 | MockRead(SYNCHRONOUS, OK), |
| 7831 | }; |
| 7832 | |
| 7833 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7834 | data_writes1, arraysize(data_writes1)); |
| 7835 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7836 | data_writes3, arraysize(data_writes3)); |
| 7837 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7838 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7839 | |
| 7840 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7841 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7842 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7843 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7844 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7845 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7846 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7847 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7848 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7849 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7850 | |
| 7851 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7852 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7853 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7854 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7855 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7856 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7857 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7858 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7859 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7860 | |
| 7861 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7862 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7863 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7864 | |
| 7865 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7866 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7867 | } |
| 7868 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7869 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7870 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7871 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7872 | |
| 7873 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7874 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7875 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7876 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7877 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7878 | request.traffic_annotation = |
| 7879 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7880 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7881 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7882 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7883 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7884 | MockWrite( |
| 7885 | "GET /x/y/z HTTP/1.1\r\n" |
| 7886 | "Host: www.example.org\r\n" |
| 7887 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7888 | }; |
| 7889 | |
| 7890 | MockRead data_reads1[] = { |
| 7891 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7892 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7893 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7894 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7895 | }; |
| 7896 | |
| 7897 | // Resend with authorization (username=foo, password=bar) |
| 7898 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7899 | MockWrite( |
| 7900 | "GET /x/y/z HTTP/1.1\r\n" |
| 7901 | "Host: www.example.org\r\n" |
| 7902 | "Connection: keep-alive\r\n" |
| 7903 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7904 | }; |
| 7905 | |
| 7906 | // Sever accepts the authorization. |
| 7907 | MockRead data_reads2[] = { |
| 7908 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7909 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7910 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7911 | }; |
| 7912 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7913 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7914 | data_writes1, arraysize(data_writes1)); |
| 7915 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7916 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7917 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7918 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7919 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7920 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7921 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7922 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7923 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7924 | |
| 7925 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7926 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7927 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7928 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7929 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7930 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7931 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7932 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7933 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7934 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7935 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7936 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7937 | |
| 7938 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7939 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7940 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7941 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7942 | ASSERT_TRUE(response); |
| 7943 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7944 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7945 | } |
| 7946 | |
| 7947 | // ------------------------------------------------------------------------ |
| 7948 | |
| 7949 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7950 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7951 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7952 | request.method = "GET"; |
| 7953 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7954 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7955 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7956 | request.traffic_annotation = |
| 7957 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7958 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7959 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7960 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7961 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7962 | MockWrite( |
| 7963 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7964 | "Host: www.example.org\r\n" |
| 7965 | "Connection: keep-alive\r\n" |
| 7966 | // Send preemptive authorization for MyRealm1 |
| 7967 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7968 | }; |
| 7969 | |
| 7970 | // The server didn't like the preemptive authorization, and |
| 7971 | // challenges us for a different realm (MyRealm2). |
| 7972 | MockRead data_reads1[] = { |
| 7973 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7974 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7975 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7976 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7977 | }; |
| 7978 | |
| 7979 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7980 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7981 | MockWrite( |
| 7982 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7983 | "Host: www.example.org\r\n" |
| 7984 | "Connection: keep-alive\r\n" |
| 7985 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7986 | }; |
| 7987 | |
| 7988 | // Sever accepts the authorization. |
| 7989 | MockRead data_reads2[] = { |
| 7990 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7991 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7992 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7993 | }; |
| 7994 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7995 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7996 | data_writes1, arraysize(data_writes1)); |
| 7997 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7998 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7999 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8000 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8002 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8003 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8004 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8005 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8006 | |
| 8007 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8008 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8009 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8010 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8011 | ASSERT_TRUE(response); |
| 8012 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8013 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8014 | EXPECT_EQ("http://www.example.org", |
| 8015 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8016 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8017 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8018 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8019 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8020 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8021 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8022 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8023 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8024 | |
| 8025 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8026 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8027 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8028 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8029 | ASSERT_TRUE(response); |
| 8030 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8031 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8032 | } |
| 8033 | |
| 8034 | // ------------------------------------------------------------------------ |
| 8035 | |
| 8036 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8037 | // succeed with preemptive authorization. |
| 8038 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8039 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8040 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8041 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8042 | request.traffic_annotation = |
| 8043 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8044 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8045 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8046 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8047 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8048 | MockWrite( |
| 8049 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8050 | "Host: www.example.org\r\n" |
| 8051 | "Connection: keep-alive\r\n" |
| 8052 | // The authorization for MyRealm1 gets sent preemptively |
| 8053 | // (since the url is in the same protection space) |
| 8054 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8055 | }; |
| 8056 | |
| 8057 | // Sever accepts the preemptive authorization |
| 8058 | MockRead data_reads1[] = { |
| 8059 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8060 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8061 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8062 | }; |
| 8063 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8064 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8065 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8066 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8067 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8068 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8069 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8070 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8071 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8072 | |
| 8073 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8074 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8075 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8076 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8077 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8078 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8079 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8080 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8081 | } |
| 8082 | |
| 8083 | // ------------------------------------------------------------------------ |
| 8084 | |
| 8085 | // Transaction 4: request another URL in MyRealm (however the |
| 8086 | // url is not known to belong to the protection space, so no pre-auth). |
| 8087 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8088 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8089 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8090 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8091 | request.traffic_annotation = |
| 8092 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8093 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8094 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8095 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8096 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8097 | MockWrite( |
| 8098 | "GET /x/1 HTTP/1.1\r\n" |
| 8099 | "Host: www.example.org\r\n" |
| 8100 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8101 | }; |
| 8102 | |
| 8103 | MockRead data_reads1[] = { |
| 8104 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8105 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8106 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8107 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8108 | }; |
| 8109 | |
| 8110 | // Resend with authorization from MyRealm's cache. |
| 8111 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8112 | MockWrite( |
| 8113 | "GET /x/1 HTTP/1.1\r\n" |
| 8114 | "Host: www.example.org\r\n" |
| 8115 | "Connection: keep-alive\r\n" |
| 8116 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8117 | }; |
| 8118 | |
| 8119 | // Sever accepts the authorization. |
| 8120 | MockRead data_reads2[] = { |
| 8121 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8122 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8123 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8124 | }; |
| 8125 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8126 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8127 | data_writes1, arraysize(data_writes1)); |
| 8128 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8129 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8130 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8131 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8133 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8134 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8135 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8136 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8137 | |
| 8138 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8139 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8140 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8141 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8142 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8143 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8144 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8145 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8146 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8147 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8148 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8149 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8150 | ASSERT_TRUE(response); |
| 8151 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8152 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8153 | } |
| 8154 | |
| 8155 | // ------------------------------------------------------------------------ |
| 8156 | |
| 8157 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 8158 | // cached identity. Should invalidate and re-prompt. |
| 8159 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8160 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8161 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8162 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8163 | request.traffic_annotation = |
| 8164 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8166 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8167 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8168 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8169 | MockWrite( |
| 8170 | "GET /p/q/t HTTP/1.1\r\n" |
| 8171 | "Host: www.example.org\r\n" |
| 8172 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8173 | }; |
| 8174 | |
| 8175 | MockRead data_reads1[] = { |
| 8176 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8177 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8178 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8179 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8180 | }; |
| 8181 | |
| 8182 | // Resend with authorization from cache for MyRealm. |
| 8183 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8184 | MockWrite( |
| 8185 | "GET /p/q/t HTTP/1.1\r\n" |
| 8186 | "Host: www.example.org\r\n" |
| 8187 | "Connection: keep-alive\r\n" |
| 8188 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8189 | }; |
| 8190 | |
| 8191 | // Sever rejects the authorization. |
| 8192 | MockRead data_reads2[] = { |
| 8193 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8194 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8195 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8196 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8197 | }; |
| 8198 | |
| 8199 | // At this point we should prompt for new credentials for MyRealm. |
| 8200 | // Restart with username=foo3, password=foo4. |
| 8201 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8202 | MockWrite( |
| 8203 | "GET /p/q/t HTTP/1.1\r\n" |
| 8204 | "Host: www.example.org\r\n" |
| 8205 | "Connection: keep-alive\r\n" |
| 8206 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8207 | }; |
| 8208 | |
| 8209 | // Sever accepts the authorization. |
| 8210 | MockRead data_reads3[] = { |
| 8211 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8212 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8213 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8214 | }; |
| 8215 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8216 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8217 | data_writes1, arraysize(data_writes1)); |
| 8218 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8219 | data_writes2, arraysize(data_writes2)); |
| 8220 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8221 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8222 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8223 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8224 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8226 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8227 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8228 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8229 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8230 | |
| 8231 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8232 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8233 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8234 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8235 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8236 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8237 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8238 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8239 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8240 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8241 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8242 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8243 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8244 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8245 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8246 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8247 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8248 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 8249 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8250 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8251 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8252 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8253 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8254 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8255 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8256 | ASSERT_TRUE(response); |
| 8257 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8258 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8259 | } |
| 8260 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8261 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8262 | // Tests that nonce count increments when multiple auth attempts |
| 8263 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8264 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 8265 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 8266 | new HttpAuthHandlerDigest::Factory(); |
| 8267 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 8268 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 8269 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8270 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8271 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8272 | |
| 8273 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8274 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8275 | HttpRequestInfo request; |
| 8276 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8277 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8278 | request.traffic_annotation = |
| 8279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8280 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8281 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8282 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8283 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8284 | MockWrite( |
| 8285 | "GET /x/y/z HTTP/1.1\r\n" |
| 8286 | "Host: www.example.org\r\n" |
| 8287 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8288 | }; |
| 8289 | |
| 8290 | MockRead data_reads1[] = { |
| 8291 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8292 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 8293 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8294 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8295 | }; |
| 8296 | |
| 8297 | // Resend with authorization (username=foo, password=bar) |
| 8298 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8299 | MockWrite( |
| 8300 | "GET /x/y/z HTTP/1.1\r\n" |
| 8301 | "Host: www.example.org\r\n" |
| 8302 | "Connection: keep-alive\r\n" |
| 8303 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8304 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 8305 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 8306 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8307 | }; |
| 8308 | |
| 8309 | // Sever accepts the authorization. |
| 8310 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8311 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8312 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8313 | }; |
| 8314 | |
| 8315 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8316 | data_writes1, arraysize(data_writes1)); |
| 8317 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8318 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8319 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8320 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8321 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8322 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8323 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8324 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8325 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8326 | |
| 8327 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8328 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8329 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8330 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8331 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8332 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8333 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8334 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8335 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8336 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8337 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8338 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8339 | |
| 8340 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8341 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8342 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8343 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8344 | ASSERT_TRUE(response); |
| 8345 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8346 | } |
| 8347 | |
| 8348 | // ------------------------------------------------------------------------ |
| 8349 | |
| 8350 | // Transaction 2: Request another resource in digestive's protection space. |
| 8351 | // This will preemptively add an Authorization header which should have an |
| 8352 | // "nc" value of 2 (as compared to 1 in the first use. |
| 8353 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8354 | HttpRequestInfo request; |
| 8355 | request.method = "GET"; |
| 8356 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8357 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8358 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8359 | request.traffic_annotation = |
| 8360 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8361 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8362 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8363 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8364 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8365 | MockWrite( |
| 8366 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8367 | "Host: www.example.org\r\n" |
| 8368 | "Connection: keep-alive\r\n" |
| 8369 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8370 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 8371 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 8372 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8373 | }; |
| 8374 | |
| 8375 | // Sever accepts the authorization. |
| 8376 | MockRead data_reads1[] = { |
| 8377 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8378 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8379 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8380 | }; |
| 8381 | |
| 8382 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8383 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8384 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8385 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8386 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8387 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8388 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8389 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8390 | |
| 8391 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8392 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8394 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8395 | ASSERT_TRUE(response); |
| 8396 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8397 | } |
| 8398 | } |
| 8399 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8400 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8401 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8402 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8403 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8404 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8405 | |
| 8406 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8407 | trans.read_buf_ = new IOBuffer(15); |
| 8408 | trans.read_buf_len_ = 15; |
| 8409 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8410 | |
| 8411 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8412 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8413 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8414 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8415 | response->response_time = base::Time::Now(); |
| 8416 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8417 | |
| 8418 | { // Setup state for response_.vary_data |
| 8419 | HttpRequestInfo request; |
| 8420 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 8421 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 8422 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8423 | request.extra_headers.SetHeader("Foo", "1"); |
| 8424 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8425 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8426 | } |
| 8427 | |
| 8428 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8429 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8430 | |
| 8431 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8432 | EXPECT_FALSE(trans.read_buf_); |
| 8433 | EXPECT_EQ(0, trans.read_buf_len_); |
| 8434 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8435 | EXPECT_FALSE(response->auth_challenge); |
| 8436 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 8437 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8438 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8439 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8440 | } |
| 8441 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8442 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8443 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8444 | HttpRequestInfo request; |
| 8445 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8446 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8447 | request.traffic_annotation = |
| 8448 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8449 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8451 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8452 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8453 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8454 | MockWrite( |
| 8455 | "GET / HTTP/1.1\r\n" |
| 8456 | "Host: www.example.org\r\n" |
| 8457 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8458 | }; |
| 8459 | |
| 8460 | MockRead data_reads[] = { |
| 8461 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8462 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8463 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8464 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8465 | }; |
| 8466 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 8467 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8468 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8469 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8470 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8471 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8472 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8473 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8474 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8475 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8476 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8477 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8478 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8479 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8480 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8482 | |
| 8483 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8484 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8485 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8486 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8487 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8488 | |
| 8489 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8490 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8491 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8492 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8493 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8494 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8495 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8496 | } |
| 8497 | |
| 8498 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 8499 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8500 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8501 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8502 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8503 | |
| 8504 | HttpRequestInfo request; |
| 8505 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8506 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8507 | request.traffic_annotation = |
| 8508 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8509 | |
| 8510 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8511 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8512 | "Host: www.example.org:443\r\n" |
| 8513 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8514 | }; |
| 8515 | |
| 8516 | MockRead proxy_reads[] = { |
| 8517 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8518 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8519 | }; |
| 8520 | |
| 8521 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8522 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8523 | "Host: www.example.org:443\r\n" |
| 8524 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8525 | MockWrite("GET / HTTP/1.1\r\n" |
| 8526 | "Host: www.example.org\r\n" |
| 8527 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8528 | }; |
| 8529 | |
| 8530 | MockRead data_reads[] = { |
| 8531 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 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] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8538 | StaticSocketDataProvider ssl_bad_certificate( |
| 8539 | proxy_reads, arraysize(proxy_reads), |
| 8540 | proxy_writes, arraysize(proxy_writes)); |
| 8541 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8542 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8543 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8544 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8545 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8546 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8547 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8548 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8549 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8550 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8551 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8552 | |
| 8553 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8554 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8555 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8556 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8557 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8558 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8559 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8560 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8561 | |
| 8562 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8563 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8564 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8565 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8566 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8567 | |
| 8568 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8569 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8570 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8571 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8572 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8573 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8574 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8575 | } |
| 8576 | } |
| 8577 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8578 | |
| 8579 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8580 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8581 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8582 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8583 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8584 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8585 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8586 | |
| 8587 | HttpRequestInfo request; |
| 8588 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8589 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8590 | request.traffic_annotation = |
| 8591 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8592 | |
| 8593 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8594 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8595 | "Host: www.example.org:443\r\n" |
| 8596 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8597 | MockWrite("GET / HTTP/1.1\r\n" |
| 8598 | "Host: www.example.org\r\n" |
| 8599 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8600 | }; |
| 8601 | |
| 8602 | MockRead data_reads[] = { |
| 8603 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8604 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8605 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8606 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8607 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8608 | }; |
| 8609 | |
| 8610 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8611 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8612 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8613 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8614 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8615 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8616 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8617 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8618 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8619 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8620 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8621 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8622 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8623 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8624 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8625 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8626 | |
| 8627 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8628 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8629 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8630 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8631 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8632 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8633 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8634 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8635 | EXPECT_EQ(200, response->headers->response_code()); |
| 8636 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8637 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8638 | |
| 8639 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8640 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8641 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8642 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8643 | } |
| 8644 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8645 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8646 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8647 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8648 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8649 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8650 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8651 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8652 | |
| 8653 | HttpRequestInfo request; |
| 8654 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8655 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8656 | request.traffic_annotation = |
| 8657 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8658 | |
| 8659 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8660 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8661 | "Host: www.example.org:443\r\n" |
| 8662 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8663 | }; |
| 8664 | |
| 8665 | MockRead data_reads[] = { |
| 8666 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8667 | MockRead("Location: http://login.example.com/\r\n"), |
| 8668 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8669 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8670 | }; |
| 8671 | |
| 8672 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8673 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8674 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8675 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8676 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8677 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8678 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8679 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8680 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8681 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8682 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8683 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8684 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8685 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8686 | |
| 8687 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8688 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8689 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8690 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8691 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8692 | |
| 8693 | EXPECT_EQ(302, response->headers->response_code()); |
| 8694 | std::string url; |
| 8695 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8696 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8697 | |
| 8698 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8699 | // timing for the proxy connection instead of the connection to the host, |
| 8700 | // and no send / receive times. |
| 8701 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8702 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8703 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8704 | |
| 8705 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8706 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8707 | |
| 8708 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8709 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8710 | load_timing_info.proxy_resolve_end); |
| 8711 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8712 | load_timing_info.connect_timing.connect_start); |
| 8713 | ExpectConnectTimingHasTimes( |
| 8714 | load_timing_info.connect_timing, |
| 8715 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8716 | |
| 8717 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8718 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8719 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8720 | } |
| 8721 | |
| 8722 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8723 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8724 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8725 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8726 | |
| 8727 | HttpRequestInfo request; |
| 8728 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8729 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8730 | request.traffic_annotation = |
| 8731 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8732 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8733 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8734 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8735 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8736 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8737 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8738 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8739 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8740 | }; |
| 8741 | |
| 8742 | static const char* const kExtraHeaders[] = { |
| 8743 | "location", |
| 8744 | "http://login.example.com/", |
| 8745 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8746 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8747 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8748 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8749 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8750 | }; |
| 8751 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8752 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8753 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8754 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8755 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8756 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8757 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8758 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8759 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8760 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8761 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8763 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8764 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8765 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8766 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8767 | |
| 8768 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8769 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8770 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8771 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8772 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8773 | |
| 8774 | EXPECT_EQ(302, response->headers->response_code()); |
| 8775 | std::string url; |
| 8776 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8777 | EXPECT_EQ("http://login.example.com/", url); |
| 8778 | } |
| 8779 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8780 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8781 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8782 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8783 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8784 | |
| 8785 | HttpRequestInfo request; |
| 8786 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8787 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8788 | request.traffic_annotation = |
| 8789 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8790 | |
| 8791 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8792 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8793 | "Host: www.example.org:443\r\n" |
| 8794 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8795 | }; |
| 8796 | |
| 8797 | MockRead data_reads[] = { |
| 8798 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8799 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8800 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8802 | }; |
| 8803 | |
| 8804 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8805 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8806 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8807 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8809 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8811 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8812 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8813 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8814 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8815 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8816 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8818 | |
| 8819 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8820 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8821 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8822 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8823 | } |
| 8824 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8825 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8826 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8827 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8828 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8829 | |
| 8830 | HttpRequestInfo request; |
| 8831 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8832 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8833 | request.traffic_annotation = |
| 8834 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8835 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8836 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8837 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8838 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8839 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8840 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8841 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8842 | }; |
| 8843 | |
| 8844 | static const char* const kExtraHeaders[] = { |
| 8845 | "location", |
| 8846 | "http://login.example.com/", |
| 8847 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8848 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8849 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8850 | SpdySerializedFrame body( |
| 8851 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8852 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8853 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8854 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8855 | }; |
| 8856 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8857 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8858 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8859 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8860 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8861 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8862 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8863 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8864 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8865 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8866 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8867 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8868 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8869 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8870 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8871 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8872 | |
| 8873 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8874 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8875 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8876 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8877 | } |
| 8878 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8879 | // Test the request-challenge-retry sequence for basic auth, through |
| 8880 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8881 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8882 | HttpRequestInfo request; |
| 8883 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8884 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8885 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8886 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8887 | request.traffic_annotation = |
| 8888 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8889 | |
| 8890 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8891 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8892 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8893 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8894 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8895 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8896 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8897 | |
| 8898 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8899 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8900 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8901 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8902 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8903 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8904 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8905 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8906 | // be issuing -- the final header line contains the credentials. |
| 8907 | const char* const kAuthCredentials[] = { |
| 8908 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8909 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8910 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8911 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8912 | HostPortPair("www.example.org", 443))); |
| 8913 | // fetch https://www.example.org/ via HTTP |
| 8914 | const char get[] = |
| 8915 | "GET / HTTP/1.1\r\n" |
| 8916 | "Host: www.example.org\r\n" |
| 8917 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8918 | SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8919 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8920 | |
| 8921 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8922 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8923 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8924 | }; |
| 8925 | |
| 8926 | // The proxy responds to the connect with a 407, using a persistent |
| 8927 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8928 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8929 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8930 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8931 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8932 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8933 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8934 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8935 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8936 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8937 | "Content-Length: 5\r\n\r\n"; |
| 8938 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8939 | SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8940 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8941 | SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8942 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8943 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8944 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8945 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8946 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8947 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8948 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8949 | }; |
| 8950 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8951 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8952 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8953 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8954 | // Negotiate SPDY to the proxy |
| 8955 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8956 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8957 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8958 | // Vanilla SSL to the server |
| 8959 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8960 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8961 | |
| 8962 | TestCompletionCallback callback1; |
| 8963 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8964 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8965 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8966 | |
| 8967 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8968 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8969 | |
| 8970 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8971 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8972 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8973 | log.GetEntries(&entries); |
| 8974 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8975 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8976 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8977 | ExpectLogContainsSomewhere( |
| 8978 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8979 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8980 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8981 | |
| 8982 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8983 | ASSERT_TRUE(response); |
| 8984 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8985 | EXPECT_EQ(407, response->headers->response_code()); |
| 8986 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8987 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8988 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8989 | |
| 8990 | TestCompletionCallback callback2; |
| 8991 | |
| 8992 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8993 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8995 | |
| 8996 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8997 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8998 | |
| 8999 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9000 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9001 | |
| 9002 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9003 | EXPECT_EQ(200, response->headers->response_code()); |
| 9004 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 9005 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9006 | |
| 9007 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9008 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9009 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9010 | LoadTimingInfo load_timing_info; |
| 9011 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9012 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9013 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9014 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9015 | trans.reset(); |
| 9016 | session->CloseAllConnections(); |
| 9017 | } |
| 9018 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9019 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 9020 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9021 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9022 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9023 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9024 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9025 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9026 | HttpRequestInfo request; |
| 9027 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9028 | request.traffic_annotation = |
| 9029 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9030 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9031 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9032 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9033 | push_request.method = "GET"; |
| 9034 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9035 | push_request.traffic_annotation = |
| 9036 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9037 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9038 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9039 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9040 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9041 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9042 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9043 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9044 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9045 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9046 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9047 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9048 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9049 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9050 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9051 | SpdySerializedFrame stream2_priority( |
| 9052 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9053 | |
| 9054 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9055 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9056 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9057 | }; |
| 9058 | |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9059 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
| 9060 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 9061 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9062 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9063 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9064 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9065 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9066 | |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9067 | SpdySerializedFrame stream2_body( |
| 9068 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9069 | |
| 9070 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9071 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 9072 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9073 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9074 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9075 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9076 | }; |
| 9077 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9078 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9079 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9080 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9081 | // Negotiate SPDY to the proxy |
| 9082 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9083 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9084 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9085 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9086 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9087 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9088 | TestCompletionCallback callback; |
| 9089 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9090 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9091 | |
| 9092 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9093 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9094 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9095 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9096 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9097 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9098 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9099 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9100 | |
| 9101 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9102 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9103 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 9104 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9105 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9106 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9107 | |
| 9108 | EXPECT_EQ(200, response->headers->response_code()); |
| 9109 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9110 | |
| 9111 | std::string response_data; |
| 9112 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9113 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9114 | EXPECT_EQ("hello!", response_data); |
| 9115 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9116 | LoadTimingInfo load_timing_info; |
| 9117 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9118 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9119 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9120 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9121 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9122 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9123 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 9124 | |
| 9125 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9126 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9127 | EXPECT_EQ("pushed", response_data); |
| 9128 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9129 | LoadTimingInfo push_load_timing_info; |
| 9130 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 9131 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 9132 | // The transactions should share a socket ID, despite being for different |
| 9133 | // origins. |
| 9134 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 9135 | push_load_timing_info.socket_log_id); |
| 9136 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9137 | trans.reset(); |
| 9138 | push_trans.reset(); |
| 9139 | session->CloseAllConnections(); |
| 9140 | } |
| 9141 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9142 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9143 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9144 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9145 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9146 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9147 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9148 | HttpRequestInfo request; |
| 9149 | |
| 9150 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9151 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9152 | request.traffic_annotation = |
| 9153 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9154 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9155 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9156 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9157 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9158 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9159 | |
| 9160 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9161 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9162 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9163 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9164 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9165 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9166 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9167 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9168 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 9169 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9170 | |
| 9171 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9172 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9173 | }; |
| 9174 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9175 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9176 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9177 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9178 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9179 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9180 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 9181 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9182 | |
| 9183 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9184 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9185 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 9186 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 9187 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9188 | }; |
| 9189 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9190 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9191 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9192 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9193 | // Negotiate SPDY to the proxy |
| 9194 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9195 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9197 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9198 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9199 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9200 | TestCompletionCallback callback; |
| 9201 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9202 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9203 | |
| 9204 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9205 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9206 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9207 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9208 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9209 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9210 | |
| 9211 | EXPECT_EQ(200, response->headers->response_code()); |
| 9212 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9213 | |
| 9214 | std::string response_data; |
| 9215 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9216 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9217 | EXPECT_EQ("hello!", response_data); |
| 9218 | |
| 9219 | trans.reset(); |
| 9220 | session->CloseAllConnections(); |
| 9221 | } |
| 9222 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9223 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 9224 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9225 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9226 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9227 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9228 | proxy_delegate->set_trusted_spdy_proxy( |
| 9229 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 9230 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9231 | HttpRequestInfo request; |
| 9232 | |
| 9233 | request.method = "GET"; |
| 9234 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9235 | request.traffic_annotation = |
| 9236 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9237 | |
| 9238 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9239 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9240 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9241 | BoundTestNetLog log; |
| 9242 | session_deps_.net_log = log.bound().net_log(); |
| 9243 | |
| 9244 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9245 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9246 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9247 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9248 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9249 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9250 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9251 | SpdySerializedFrame stream2_priority( |
| 9252 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9253 | |
| 9254 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9255 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9256 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9257 | }; |
| 9258 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9259 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9260 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9261 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9262 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 9263 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 9264 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9265 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9266 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9267 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9268 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9269 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9270 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9271 | |
| 9272 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9273 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9274 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9275 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9276 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9277 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9278 | }; |
| 9279 | |
| 9280 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9281 | arraysize(spdy_writes)); |
| 9282 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 9283 | // Negotiate SPDY to the proxy |
| 9284 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9285 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9286 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 9287 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9288 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9289 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9290 | TestCompletionCallback callback; |
| 9291 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9292 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9293 | |
| 9294 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9295 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9296 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9297 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9298 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9299 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9300 | |
| 9301 | EXPECT_EQ(200, response->headers->response_code()); |
| 9302 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9303 | |
| 9304 | std::string response_data; |
| 9305 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9306 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9307 | EXPECT_EQ("hello!", response_data); |
| 9308 | |
| 9309 | trans.reset(); |
| 9310 | session->CloseAllConnections(); |
| 9311 | } |
| 9312 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9313 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 9314 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9315 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9316 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9317 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9318 | |
| 9319 | HttpRequestInfo request; |
| 9320 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9321 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9322 | request.traffic_annotation = |
| 9323 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9324 | |
| 9325 | // Attempt to fetch the URL from a server with a bad cert |
| 9326 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9327 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9328 | "Host: www.example.org:443\r\n" |
| 9329 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9330 | }; |
| 9331 | |
| 9332 | MockRead bad_cert_reads[] = { |
| 9333 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9334 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9335 | }; |
| 9336 | |
| 9337 | // Attempt to fetch the URL with a good cert |
| 9338 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9339 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9340 | "Host: www.example.org:443\r\n" |
| 9341 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9342 | MockWrite("GET / HTTP/1.1\r\n" |
| 9343 | "Host: www.example.org\r\n" |
| 9344 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9345 | }; |
| 9346 | |
| 9347 | MockRead good_cert_reads[] = { |
| 9348 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9349 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9350 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9351 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9352 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9353 | }; |
| 9354 | |
| 9355 | StaticSocketDataProvider ssl_bad_certificate( |
| 9356 | bad_cert_reads, arraysize(bad_cert_reads), |
| 9357 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 9358 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 9359 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9360 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9361 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9362 | |
| 9363 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9365 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9366 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9367 | |
| 9368 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9369 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9370 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9371 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9372 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9373 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9374 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9375 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9376 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9377 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9378 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9379 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9380 | |
| 9381 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9382 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9383 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9384 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9385 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9386 | |
| 9387 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9388 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9389 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9390 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9391 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9392 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9393 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9394 | } |
| 9395 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9396 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9397 | HttpRequestInfo request; |
| 9398 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9399 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9400 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9401 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9402 | request.traffic_annotation = |
| 9403 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9406 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9407 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9408 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9409 | MockWrite( |
| 9410 | "GET / HTTP/1.1\r\n" |
| 9411 | "Host: www.example.org\r\n" |
| 9412 | "Connection: keep-alive\r\n" |
| 9413 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9414 | }; |
| 9415 | |
| 9416 | // Lastly, the server responds with the actual content. |
| 9417 | MockRead data_reads[] = { |
| 9418 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9419 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9420 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9421 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9422 | }; |
| 9423 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9424 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9425 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9426 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9428 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9429 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9430 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9431 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9432 | |
| 9433 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9434 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9435 | } |
| 9436 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9437 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9438 | HttpRequestInfo request; |
| 9439 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9440 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9441 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9442 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9443 | request.traffic_annotation = |
| 9444 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9445 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9446 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9447 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9448 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9449 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9450 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9451 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9452 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9453 | "Host: www.example.org:443\r\n" |
| 9454 | "Proxy-Connection: keep-alive\r\n" |
| 9455 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9456 | }; |
| 9457 | MockRead data_reads[] = { |
| 9458 | // Return an error, so the transaction stops here (this test isn't |
| 9459 | // interested in the rest). |
| 9460 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 9461 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9462 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 9463 | }; |
| 9464 | |
| 9465 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9466 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9467 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9469 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9470 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9471 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9472 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9473 | |
| 9474 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9475 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9476 | } |
| 9477 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9478 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9479 | HttpRequestInfo request; |
| 9480 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9481 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 9482 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 9483 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9484 | request.traffic_annotation = |
| 9485 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9486 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9487 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9488 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9489 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9490 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9491 | MockWrite( |
| 9492 | "GET / HTTP/1.1\r\n" |
| 9493 | "Host: www.example.org\r\n" |
| 9494 | "Connection: keep-alive\r\n" |
| 9495 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9496 | }; |
| 9497 | |
| 9498 | // Lastly, the server responds with the actual content. |
| 9499 | MockRead data_reads[] = { |
| 9500 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9501 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9502 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9503 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9504 | }; |
| 9505 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9506 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9507 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9508 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9509 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9510 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9511 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9512 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9513 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9514 | |
| 9515 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9516 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9517 | } |
| 9518 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9519 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9520 | HttpRequestInfo request; |
| 9521 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9522 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9523 | request.traffic_annotation = |
| 9524 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9525 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9526 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9527 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9528 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9529 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9530 | MockWrite( |
| 9531 | "POST / HTTP/1.1\r\n" |
| 9532 | "Host: www.example.org\r\n" |
| 9533 | "Connection: keep-alive\r\n" |
| 9534 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9535 | }; |
| 9536 | |
| 9537 | // Lastly, the server responds with the actual content. |
| 9538 | MockRead data_reads[] = { |
| 9539 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9540 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9541 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9542 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9543 | }; |
| 9544 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9545 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9546 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9547 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9548 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9549 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9550 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9551 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9552 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9553 | |
| 9554 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9555 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9556 | } |
| 9557 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9558 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9559 | HttpRequestInfo request; |
| 9560 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9561 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9562 | request.traffic_annotation = |
| 9563 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9564 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9565 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9566 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9567 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9568 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9569 | MockWrite( |
| 9570 | "PUT / HTTP/1.1\r\n" |
| 9571 | "Host: www.example.org\r\n" |
| 9572 | "Connection: keep-alive\r\n" |
| 9573 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9574 | }; |
| 9575 | |
| 9576 | // Lastly, the server responds with the actual content. |
| 9577 | MockRead data_reads[] = { |
| 9578 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9579 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9580 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9581 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9582 | }; |
| 9583 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9584 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9585 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9586 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9587 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9588 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9589 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9590 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9591 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9592 | |
| 9593 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9594 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9595 | } |
| 9596 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9597 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9598 | HttpRequestInfo request; |
| 9599 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9600 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9601 | request.traffic_annotation = |
| 9602 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9603 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9604 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9605 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9606 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9607 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 9608 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 9609 | "Host: www.example.org\r\n" |
| 9610 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9611 | }; |
| 9612 | |
| 9613 | // Lastly, the server responds with the actual content. |
| 9614 | MockRead data_reads[] = { |
| 9615 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9616 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9617 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9618 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9619 | }; |
| 9620 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9621 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9622 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9623 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9624 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9625 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9626 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9627 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9628 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9629 | |
| 9630 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9631 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9632 | } |
| 9633 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9634 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9635 | HttpRequestInfo request; |
| 9636 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9637 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9638 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9639 | request.traffic_annotation = |
| 9640 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9641 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9642 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9643 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9644 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9645 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9646 | MockWrite( |
| 9647 | "GET / HTTP/1.1\r\n" |
| 9648 | "Host: www.example.org\r\n" |
| 9649 | "Connection: keep-alive\r\n" |
| 9650 | "Pragma: no-cache\r\n" |
| 9651 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9652 | }; |
| 9653 | |
| 9654 | // Lastly, the server responds with the actual content. |
| 9655 | MockRead data_reads[] = { |
| 9656 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9657 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9658 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9659 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9660 | }; |
| 9661 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9662 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9663 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9664 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9665 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9666 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9667 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9668 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9669 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9670 | |
| 9671 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9672 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9673 | } |
| 9674 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9675 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9676 | HttpRequestInfo request; |
| 9677 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9678 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9679 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9680 | request.traffic_annotation = |
| 9681 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9682 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9683 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9684 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9685 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9686 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9687 | MockWrite( |
| 9688 | "GET / HTTP/1.1\r\n" |
| 9689 | "Host: www.example.org\r\n" |
| 9690 | "Connection: keep-alive\r\n" |
| 9691 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9692 | }; |
| 9693 | |
| 9694 | // Lastly, the server responds with the actual content. |
| 9695 | MockRead data_reads[] = { |
| 9696 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9697 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9698 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9699 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9700 | }; |
| 9701 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9702 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9703 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9704 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9705 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9706 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9707 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9708 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9709 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9710 | |
| 9711 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9712 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9713 | } |
| 9714 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9715 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9716 | HttpRequestInfo request; |
| 9717 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9718 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9719 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9720 | request.traffic_annotation = |
| 9721 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9722 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9723 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9724 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9725 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9726 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9727 | MockWrite( |
| 9728 | "GET / HTTP/1.1\r\n" |
| 9729 | "Host: www.example.org\r\n" |
| 9730 | "Connection: keep-alive\r\n" |
| 9731 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9732 | }; |
| 9733 | |
| 9734 | // Lastly, the server responds with the actual content. |
| 9735 | MockRead data_reads[] = { |
| 9736 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9737 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9738 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9739 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9740 | }; |
| 9741 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9742 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9743 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9744 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9745 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9746 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9747 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9748 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9749 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9750 | |
| 9751 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9752 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9753 | } |
| 9754 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9755 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9756 | HttpRequestInfo request; |
| 9757 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9758 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9759 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9760 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9761 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9762 | request.traffic_annotation = |
| 9763 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9764 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9765 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9766 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9767 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9768 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9769 | MockWrite( |
| 9770 | "GET / HTTP/1.1\r\n" |
| 9771 | "Host: www.example.org\r\n" |
| 9772 | "Connection: keep-alive\r\n" |
| 9773 | "referer: www.foo.com\r\n" |
| 9774 | "hEllo: Kitty\r\n" |
| 9775 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9776 | }; |
| 9777 | |
| 9778 | // Lastly, the server responds with the actual content. |
| 9779 | MockRead data_reads[] = { |
| 9780 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9781 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9782 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9783 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9784 | }; |
| 9785 | |
| 9786 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9787 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9788 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9790 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9791 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9792 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9794 | |
| 9795 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9796 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9797 | } |
| 9798 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9799 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9800 | HttpRequestInfo request; |
| 9801 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9802 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9803 | request.traffic_annotation = |
| 9804 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9805 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9806 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9807 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9808 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9809 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9810 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9811 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9812 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9814 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9815 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9816 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9817 | |
| 9818 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9819 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9820 | MockWrite( |
| 9821 | "GET / HTTP/1.1\r\n" |
| 9822 | "Host: www.example.org\r\n" |
| 9823 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9824 | |
| 9825 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9826 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9827 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9828 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9829 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9830 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9831 | }; |
| 9832 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9833 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9834 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9835 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9836 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9837 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9838 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9839 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9841 | |
| 9842 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9843 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9845 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9846 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9847 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9848 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9849 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9850 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9851 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9852 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9853 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9854 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9855 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9856 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9857 | EXPECT_EQ("Payload", response_text); |
| 9858 | } |
| 9859 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9860 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9861 | HttpRequestInfo request; |
| 9862 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9863 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9864 | request.traffic_annotation = |
| 9865 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9866 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9867 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9868 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9869 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9870 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9871 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9874 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9875 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9876 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9877 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9878 | |
| 9879 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9880 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9881 | arraysize(write_buffer)), |
| 9882 | MockWrite( |
| 9883 | "GET / HTTP/1.1\r\n" |
| 9884 | "Host: www.example.org\r\n" |
| 9885 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9886 | |
| 9887 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9888 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9889 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9890 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9891 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9892 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9893 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9894 | }; |
| 9895 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9896 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9897 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9898 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9899 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9900 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9901 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9902 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9903 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9904 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9905 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9907 | |
| 9908 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9909 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9910 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9911 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9912 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9913 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9914 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 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); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9918 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9919 | |
| 9920 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9921 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9922 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9923 | EXPECT_EQ("Payload", response_text); |
| 9924 | } |
| 9925 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9926 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9927 | HttpRequestInfo request; |
| 9928 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9929 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9930 | request.traffic_annotation = |
| 9931 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9932 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9933 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9934 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9935 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9936 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9937 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9938 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9939 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9940 | |
| 9941 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9942 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9943 | |
| 9944 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9945 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9946 | MockWrite( |
| 9947 | "GET / HTTP/1.1\r\n" |
| 9948 | "Host: www.example.org\r\n" |
| 9949 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9950 | |
| 9951 | MockRead data_reads[] = { |
| 9952 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9953 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9954 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9955 | MockRead("Payload"), |
| 9956 | MockRead(SYNCHRONOUS, OK) |
| 9957 | }; |
| 9958 | |
| 9959 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9960 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9961 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9962 | |
| 9963 | TestCompletionCallback callback; |
| 9964 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9965 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9966 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9967 | |
| 9968 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9969 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9970 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9971 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9972 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9973 | |
| 9974 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9975 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9976 | TestLoadTimingNotReused(load_timing_info, |
| 9977 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9978 | |
| 9979 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9980 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9981 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9982 | EXPECT_EQ("Payload", response_text); |
| 9983 | } |
| 9984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9985 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9986 | HttpRequestInfo request; |
| 9987 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9988 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9989 | request.traffic_annotation = |
| 9990 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9991 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9992 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9993 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9994 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9995 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9996 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9997 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9998 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9999 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10000 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10001 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10002 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10003 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10004 | 0x05, // Version |
| 10005 | 0x01, // Command (CONNECT) |
| 10006 | 0x00, // Reserved. |
| 10007 | 0x03, // Address type (DOMAINNAME). |
| 10008 | 0x0F, // Length of domain (15) |
| 10009 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10010 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10011 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10012 | const char kSOCKS5OkResponse[] = |
| 10013 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 10014 | |
| 10015 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10016 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10017 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 10018 | MockWrite( |
| 10019 | "GET / HTTP/1.1\r\n" |
| 10020 | "Host: www.example.org\r\n" |
| 10021 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10022 | |
| 10023 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10024 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10025 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10026 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10027 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10028 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10029 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10030 | }; |
| 10031 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10032 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10033 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10034 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10035 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10036 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10037 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10038 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10039 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10040 | |
| 10041 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10042 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10043 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10044 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10045 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10046 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10047 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10048 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10049 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10050 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10051 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10052 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10053 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10054 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10055 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10056 | EXPECT_EQ("Payload", response_text); |
| 10057 | } |
| 10058 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10059 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10060 | HttpRequestInfo request; |
| 10061 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10062 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10063 | request.traffic_annotation = |
| 10064 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10065 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10066 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10067 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10068 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10069 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10070 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10071 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10072 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10073 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10074 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10075 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10076 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10077 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10078 | 0x05, // Version |
| 10079 | 0x01, // Command (CONNECT) |
| 10080 | 0x00, // Reserved. |
| 10081 | 0x03, // Address type (DOMAINNAME). |
| 10082 | 0x0F, // Length of domain (15) |
| 10083 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10084 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10085 | }; |
| 10086 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10087 | const char kSOCKS5OkResponse[] = |
| 10088 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 10089 | |
| 10090 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10091 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10092 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 10093 | arraysize(kSOCKS5OkRequest)), |
| 10094 | MockWrite( |
| 10095 | "GET / HTTP/1.1\r\n" |
| 10096 | "Host: www.example.org\r\n" |
| 10097 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10098 | |
| 10099 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10100 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10101 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10102 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10103 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10104 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10105 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10106 | }; |
| 10107 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10108 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10109 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10110 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10111 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10112 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10113 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10115 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10116 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10117 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10119 | |
| 10120 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10121 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10122 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10123 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10124 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10125 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10126 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10127 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10128 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10129 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10130 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10131 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10132 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10133 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10134 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10135 | EXPECT_EQ("Payload", response_text); |
| 10136 | } |
| 10137 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10138 | namespace { |
| 10139 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10140 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10141 | |
| 10142 | struct GroupNameTest { |
| 10143 | std::string proxy_server; |
| 10144 | std::string url; |
| 10145 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10146 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10147 | }; |
| 10148 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10149 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10150 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10151 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10152 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10153 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10154 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10155 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10156 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10157 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10158 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10159 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10160 | |
| 10161 | return session; |
| 10162 | } |
| 10163 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10164 | int GroupNameTransactionHelper(const std::string& url, |
| 10165 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10166 | HttpRequestInfo request; |
| 10167 | request.method = "GET"; |
| 10168 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10169 | request.traffic_annotation = |
| 10170 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10172 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10173 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10174 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10175 | |
| 10176 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10177 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10178 | } |
| 10179 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10180 | } // namespace |
| 10181 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10182 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10183 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10184 | { |
| 10185 | "", // unused |
| 10186 | "http://www.example.org/direct", |
| 10187 | "www.example.org:80", |
| 10188 | false, |
| 10189 | }, |
| 10190 | { |
| 10191 | "", // unused |
| 10192 | "http://[2001:1418:13:1::25]/direct", |
| 10193 | "[2001:1418:13:1::25]:80", |
| 10194 | false, |
| 10195 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10196 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10197 | // SSL Tests |
| 10198 | { |
| 10199 | "", // unused |
| 10200 | "https://www.example.org/direct_ssl", |
| 10201 | "ssl/www.example.org:443", |
| 10202 | true, |
| 10203 | }, |
| 10204 | { |
| 10205 | "", // unused |
| 10206 | "https://[2001:1418:13:1::25]/direct", |
| 10207 | "ssl/[2001:1418:13:1::25]:443", |
| 10208 | true, |
| 10209 | }, |
| 10210 | { |
| 10211 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10212 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10213 | "ssl/host.with.alternate:443", |
| 10214 | true, |
| 10215 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10216 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10217 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10218 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10219 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10220 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10221 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10222 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10223 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10224 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10225 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10226 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10227 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10228 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10229 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10230 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10231 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 10232 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10233 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10234 | |
| 10235 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10236 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10237 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10238 | EXPECT_EQ(tests[i].expected_group_name, |
| 10239 | ssl_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10240 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10241 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10242 | transport_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10243 | } |
| 10244 | // When SSL proxy is in use, socket must be requested from |ssl_conn_pool|. |
| 10245 | EXPECT_EQ(tests[i].ssl, ssl_conn_pool->socket_requested()); |
| 10246 | // When SSL proxy is not in use, socket must be requested from |
| 10247 | // |transport_conn_pool|. |
| 10248 | EXPECT_EQ(!tests[i].ssl, transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10249 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10250 | } |
| 10251 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10252 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10253 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10254 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10255 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 10256 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10257 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10258 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10259 | // SSL Tests |
| 10260 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10261 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 10262 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10263 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10264 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10265 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10266 | "http_proxy", "https://host.with.alternate/direct", |
| 10267 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10268 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 10269 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10270 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10271 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 10272 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10273 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10274 | }; |
| 10275 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10276 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10277 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10278 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10279 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10280 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10281 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10282 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10283 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10284 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10285 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10286 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10287 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10288 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10289 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10290 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10291 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 10292 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 10293 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10294 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10295 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10296 | |
| 10297 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10298 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10299 | if (tests[i].ssl) |
| 10300 | EXPECT_EQ(tests[i].expected_group_name, |
| 10301 | ssl_conn_pool->last_group_name_received()); |
| 10302 | else |
| 10303 | EXPECT_EQ(tests[i].expected_group_name, |
| 10304 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10305 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10306 | } |
| 10307 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10308 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10309 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10310 | { |
| 10311 | "socks4://socks_proxy:1080", |
| 10312 | "http://www.example.org/socks4_direct", |
| 10313 | "socks4/www.example.org:80", |
| 10314 | false, |
| 10315 | }, |
| 10316 | { |
| 10317 | "socks5://socks_proxy:1080", |
| 10318 | "http://www.example.org/socks5_direct", |
| 10319 | "socks5/www.example.org:80", |
| 10320 | false, |
| 10321 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10322 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10323 | // SSL Tests |
| 10324 | { |
| 10325 | "socks4://socks_proxy:1080", |
| 10326 | "https://www.example.org/socks4_ssl", |
| 10327 | "socks4/ssl/www.example.org:443", |
| 10328 | true, |
| 10329 | }, |
| 10330 | { |
| 10331 | "socks5://socks_proxy:1080", |
| 10332 | "https://www.example.org/socks5_ssl", |
| 10333 | "socks5/ssl/www.example.org:443", |
| 10334 | true, |
| 10335 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10336 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10337 | { |
| 10338 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10339 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10340 | "socks4/ssl/host.with.alternate:443", |
| 10341 | true, |
| 10342 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10343 | }; |
| 10344 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10345 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10346 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10347 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10348 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10349 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10350 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 10351 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10352 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10353 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10354 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10355 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10356 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10357 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10358 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10359 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10360 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 10361 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 10362 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10363 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10364 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10365 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10366 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10367 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 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 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10376 | } |
| 10377 | } |
| 10378 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10379 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10380 | HttpRequestInfo request; |
| 10381 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10382 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10383 | request.traffic_annotation = |
| 10384 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10385 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10386 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10387 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10388 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 10389 | // This simulates failure resolving all hostnames; that means we will fail |
| 10390 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10391 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10392 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10393 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10394 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10395 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10396 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10397 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10398 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10399 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10400 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10401 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10402 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10403 | } |
| 10404 | |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame^] | 10405 | // LOAD_BYPASS_CACHE should trigger the host cache bypass. |
| 10406 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10407 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10408 | HttpRequestInfo request_info; |
| 10409 | request_info.method = "GET"; |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame^] | 10410 | request_info.load_flags = LOAD_BYPASS_CACHE; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10411 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10412 | request_info.traffic_annotation = |
| 10413 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10414 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 10415 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10416 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10417 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10418 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10419 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10420 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10421 | // 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] | 10422 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10423 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10424 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10425 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10426 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10427 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10428 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10429 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10430 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10431 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10432 | |
| 10433 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 10434 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10435 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10436 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10437 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10438 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10439 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10440 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10441 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10442 | // 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] | 10443 | // we can tell if the next lookup hit the cache, or the "network". |
| 10444 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10445 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10446 | |
| 10447 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 10448 | // 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] | 10449 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10450 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10451 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10452 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10453 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10454 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10455 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10456 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10457 | |
| 10458 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10459 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10460 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10461 | } |
| 10462 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10463 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10464 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10465 | HttpRequestInfo request; |
| 10466 | request.method = "GET"; |
| 10467 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10468 | request.traffic_annotation = |
| 10469 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10470 | |
| 10471 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10472 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10473 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10474 | StaticSocketDataProvider data(NULL, 0, |
| 10475 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10476 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10477 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10478 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10479 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10480 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10481 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10482 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10483 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10484 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10485 | |
| 10486 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10487 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10488 | |
| 10489 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10490 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10491 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10492 | } |
| 10493 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10494 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10495 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10496 | HttpRequestInfo request; |
| 10497 | request.method = "GET"; |
| 10498 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10499 | request.traffic_annotation = |
| 10500 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10501 | |
| 10502 | MockRead data_reads[] = { |
| 10503 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10504 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10505 | }; |
| 10506 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10507 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10508 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10509 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10510 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10511 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10512 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10513 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10514 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10515 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10516 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10517 | |
| 10518 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10519 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10520 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10521 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10522 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10523 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10524 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10525 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10526 | |
| 10527 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10528 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10529 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10530 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10531 | |
| 10532 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10533 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10534 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10535 | } |
| 10536 | |
| 10537 | // Make sure that a dropped connection while draining the body for auth |
| 10538 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10539 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10540 | HttpRequestInfo request; |
| 10541 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10542 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10543 | request.traffic_annotation = |
| 10544 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10545 | |
| 10546 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10547 | MockWrite( |
| 10548 | "GET / HTTP/1.1\r\n" |
| 10549 | "Host: www.example.org\r\n" |
| 10550 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10551 | }; |
| 10552 | |
| 10553 | MockRead data_reads1[] = { |
| 10554 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 10555 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10556 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10557 | MockRead("Content-Length: 14\r\n\r\n"), |
| 10558 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10559 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10560 | }; |
| 10561 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10562 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10563 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10564 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10565 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10566 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10567 | // be issuing -- the final header line contains the credentials. |
| 10568 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10569 | MockWrite( |
| 10570 | "GET / HTTP/1.1\r\n" |
| 10571 | "Host: www.example.org\r\n" |
| 10572 | "Connection: keep-alive\r\n" |
| 10573 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10574 | }; |
| 10575 | |
| 10576 | // Lastly, the server responds with the actual content. |
| 10577 | MockRead data_reads2[] = { |
| 10578 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10579 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10580 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10581 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10582 | }; |
| 10583 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10584 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10585 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10586 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10587 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10589 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10590 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10591 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10592 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10593 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10594 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10595 | |
| 10596 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10597 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10598 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10599 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10600 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10601 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10602 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10603 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10604 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10605 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10606 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10607 | |
| 10608 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10609 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10610 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10611 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10612 | ASSERT_TRUE(response); |
| 10613 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10614 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10615 | } |
| 10616 | |
| 10617 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10618 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10619 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10620 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10621 | |
| 10622 | HttpRequestInfo request; |
| 10623 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10624 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10625 | request.traffic_annotation = |
| 10626 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10627 | |
| 10628 | MockRead proxy_reads[] = { |
| 10629 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10630 | MockRead(SYNCHRONOUS, OK) |
[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 data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10634 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10635 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10636 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10637 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10638 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10639 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10640 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10641 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10642 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10643 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10644 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10645 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10646 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10648 | |
| 10649 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10650 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10651 | } |
| 10652 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10653 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10654 | HttpRequestInfo request; |
| 10655 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10656 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10657 | request.traffic_annotation = |
| 10658 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10659 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10660 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10661 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10662 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10663 | MockRead data_reads[] = { |
| 10664 | 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] | 10665 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10666 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10667 | |
| 10668 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10669 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10670 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10671 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10672 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10673 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10674 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10675 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10676 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10677 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10678 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10679 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10680 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10681 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10682 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10683 | |
| 10684 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10685 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10686 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10687 | } |
| 10688 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10689 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10690 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10691 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10692 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10693 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10694 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10695 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10696 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10697 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10698 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10699 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10700 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10701 | |
| 10702 | HttpRequestInfo request; |
| 10703 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10704 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10705 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10706 | request.traffic_annotation = |
| 10707 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10708 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10709 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10710 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10711 | |
| 10712 | MockRead data_reads[] = { |
| 10713 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10714 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10715 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10716 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10717 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10718 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10719 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10720 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10721 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10722 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10723 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10724 | |
| 10725 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10726 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10727 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10728 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10729 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10730 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10731 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10732 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10733 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10734 | } |
| 10735 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10736 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10737 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10738 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10739 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10740 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10741 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10742 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10743 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10744 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10745 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10746 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10747 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10748 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10749 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10750 | |
| 10751 | HttpRequestInfo request; |
| 10752 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10753 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10754 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10755 | request.traffic_annotation = |
| 10756 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10757 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10758 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10759 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10760 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10761 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10762 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10763 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10764 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10765 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10766 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10767 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10768 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10769 | |
| 10770 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10771 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10772 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10773 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10774 | } |
| 10775 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10776 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10777 | class FakeUploadElementReader : public UploadElementReader { |
| 10778 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 10779 | FakeUploadElementReader() = default; |
| 10780 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10781 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10782 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10783 | |
| 10784 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10785 | int Init(CompletionOnceCallback callback) override { |
| 10786 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10787 | return ERR_IO_PENDING; |
| 10788 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10789 | uint64_t GetContentLength() const override { return 0; } |
| 10790 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10791 | int Read(IOBuffer* buf, |
| 10792 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10793 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10794 | return ERR_FAILED; |
| 10795 | } |
| 10796 | |
| 10797 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10798 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10799 | }; |
| 10800 | |
| 10801 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10802 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10803 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10804 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10805 | |
| 10806 | HttpRequestInfo request; |
| 10807 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10808 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10809 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10810 | request.traffic_annotation = |
| 10811 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10812 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10813 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10814 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10815 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10816 | |
| 10817 | StaticSocketDataProvider data; |
| 10818 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10819 | |
| 10820 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10821 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10823 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10824 | |
| 10825 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10826 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 10827 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10828 | |
| 10829 | // Return Init()'s result after the transaction gets destroyed. |
| 10830 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10831 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10832 | } |
| 10833 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10834 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10835 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10836 | HttpRequestInfo request; |
| 10837 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10838 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10839 | request.traffic_annotation = |
| 10840 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10841 | |
| 10842 | // First transaction will request a resource and receive a Basic challenge |
| 10843 | // with realm="first_realm". |
| 10844 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10845 | MockWrite( |
| 10846 | "GET / HTTP/1.1\r\n" |
| 10847 | "Host: www.example.org\r\n" |
| 10848 | "Connection: keep-alive\r\n" |
| 10849 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10850 | }; |
| 10851 | MockRead data_reads1[] = { |
| 10852 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10853 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10854 | "\r\n"), |
| 10855 | }; |
| 10856 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10857 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10858 | // for first_realm. The server will reject and provide a challenge with |
| 10859 | // second_realm. |
| 10860 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10861 | MockWrite( |
| 10862 | "GET / HTTP/1.1\r\n" |
| 10863 | "Host: www.example.org\r\n" |
| 10864 | "Connection: keep-alive\r\n" |
| 10865 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10866 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10867 | }; |
| 10868 | MockRead data_reads2[] = { |
| 10869 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10870 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10871 | "\r\n"), |
| 10872 | }; |
| 10873 | |
| 10874 | // This again fails, and goes back to first_realm. Make sure that the |
| 10875 | // entry is removed from cache. |
| 10876 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10877 | MockWrite( |
| 10878 | "GET / HTTP/1.1\r\n" |
| 10879 | "Host: www.example.org\r\n" |
| 10880 | "Connection: keep-alive\r\n" |
| 10881 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10882 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10883 | }; |
| 10884 | MockRead data_reads3[] = { |
| 10885 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10886 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10887 | "\r\n"), |
| 10888 | }; |
| 10889 | |
| 10890 | // Try one last time (with the correct password) and get the resource. |
| 10891 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10892 | MockWrite( |
| 10893 | "GET / HTTP/1.1\r\n" |
| 10894 | "Host: www.example.org\r\n" |
| 10895 | "Connection: keep-alive\r\n" |
| 10896 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10897 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10898 | }; |
| 10899 | MockRead data_reads4[] = { |
| 10900 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10901 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10902 | "Content-Length: 5\r\n" |
| 10903 | "\r\n" |
| 10904 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10905 | }; |
| 10906 | |
| 10907 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10908 | data_writes1, arraysize(data_writes1)); |
| 10909 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10910 | data_writes2, arraysize(data_writes2)); |
| 10911 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 10912 | data_writes3, arraysize(data_writes3)); |
| 10913 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 10914 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10915 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10916 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10917 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10918 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10919 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10920 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10921 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10922 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10923 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10924 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10925 | // Issue the first request with Authorize headers. There should be a |
| 10926 | // password prompt for first_realm waiting to be filled in after the |
| 10927 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10928 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10929 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10930 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10931 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10932 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10933 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10934 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10935 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10936 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10937 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10938 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10939 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10940 | |
| 10941 | // Issue the second request with an incorrect password. There should be a |
| 10942 | // password prompt for second_realm waiting to be filled in after the |
| 10943 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10944 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10945 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10946 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10947 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10948 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10949 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10950 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10951 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10952 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10953 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10954 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10955 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10956 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10957 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10958 | |
| 10959 | // Issue the third request with another incorrect password. There should be |
| 10960 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10961 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10962 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10963 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10964 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10965 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10966 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10967 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10968 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10969 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10970 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10971 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10972 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10973 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10974 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10975 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10976 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10977 | |
| 10978 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10979 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10980 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10981 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10982 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10983 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10984 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10985 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10986 | ASSERT_TRUE(response); |
| 10987 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10988 | } |
| 10989 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10990 | // Regression test for https://crbug.com/754395. |
| 10991 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 10992 | MockRead data_reads[] = { |
| 10993 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10994 | MockRead(kAlternativeServiceHttpHeader), |
| 10995 | MockRead("\r\n"), |
| 10996 | MockRead("hello world"), |
| 10997 | MockRead(SYNCHRONOUS, OK), |
| 10998 | }; |
| 10999 | |
| 11000 | HttpRequestInfo request; |
| 11001 | request.method = "GET"; |
| 11002 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11003 | request.traffic_annotation = |
| 11004 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11005 | |
| 11006 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11007 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11008 | |
| 11009 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11010 | ssl.ssl_info.cert = |
| 11011 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11012 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11013 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11014 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11015 | |
| 11016 | TestCompletionCallback callback; |
| 11017 | |
| 11018 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11019 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11020 | |
| 11021 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11023 | |
| 11024 | url::SchemeHostPort test_server(request.url); |
| 11025 | HttpServerProperties* http_server_properties = |
| 11026 | session->http_server_properties(); |
| 11027 | EXPECT_TRUE( |
| 11028 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11029 | |
| 11030 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11031 | |
| 11032 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11033 | ASSERT_TRUE(response); |
| 11034 | ASSERT_TRUE(response->headers); |
| 11035 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11036 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11037 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11038 | |
| 11039 | std::string response_data; |
| 11040 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11041 | EXPECT_EQ("hello world", response_data); |
| 11042 | |
| 11043 | EXPECT_TRUE( |
| 11044 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11045 | } |
| 11046 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11047 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11048 | MockRead data_reads[] = { |
| 11049 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11050 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11051 | MockRead("\r\n"), |
| 11052 | MockRead("hello world"), |
| 11053 | MockRead(SYNCHRONOUS, OK), |
| 11054 | }; |
| 11055 | |
| 11056 | HttpRequestInfo request; |
| 11057 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11058 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11059 | request.traffic_annotation = |
| 11060 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11061 | |
| 11062 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11063 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11064 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11065 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11066 | ssl.ssl_info.cert = |
| 11067 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11068 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11069 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11070 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11071 | TestCompletionCallback callback; |
| 11072 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11073 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11074 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11075 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11076 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11077 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11078 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11079 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11080 | HttpServerProperties* http_server_properties = |
| 11081 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11082 | EXPECT_TRUE( |
| 11083 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11084 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11085 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11086 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11087 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11088 | ASSERT_TRUE(response); |
| 11089 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11090 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11091 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11092 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11093 | |
| 11094 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11095 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11096 | EXPECT_EQ("hello world", response_data); |
| 11097 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11098 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11099 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11100 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11101 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 11102 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11103 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11104 | } |
| 11105 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11106 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11107 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11108 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11109 | MockRead data_reads[] = { |
| 11110 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11111 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11112 | MockRead("\r\n"), |
| 11113 | MockRead("hello world"), |
| 11114 | MockRead(SYNCHRONOUS, OK), |
| 11115 | }; |
| 11116 | |
| 11117 | HttpRequestInfo request; |
| 11118 | request.method = "GET"; |
| 11119 | request.url = GURL("http://www.example.org/"); |
| 11120 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11121 | request.traffic_annotation = |
| 11122 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11123 | |
| 11124 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11125 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11126 | |
| 11127 | TestCompletionCallback callback; |
| 11128 | |
| 11129 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11130 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11131 | |
| 11132 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11133 | HttpServerProperties* http_server_properties = |
| 11134 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11135 | EXPECT_TRUE( |
| 11136 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11137 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11138 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11139 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11140 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11141 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11142 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11143 | ASSERT_TRUE(response); |
| 11144 | ASSERT_TRUE(response->headers); |
| 11145 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11146 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11147 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11148 | |
| 11149 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11150 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11151 | EXPECT_EQ("hello world", response_data); |
| 11152 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11153 | EXPECT_TRUE( |
| 11154 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11155 | } |
| 11156 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11157 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11158 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11159 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11160 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11161 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11162 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11163 | HttpRequestInfo request; |
| 11164 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11165 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11166 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11167 | request.traffic_annotation = |
| 11168 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11169 | |
| 11170 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11171 | StaticSocketDataProvider first_data; |
| 11172 | first_data.set_connect_data(mock_connect); |
| 11173 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11174 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11175 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11176 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11177 | |
| 11178 | MockRead data_reads[] = { |
| 11179 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11180 | MockRead(ASYNC, OK), |
| 11181 | }; |
| 11182 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 11183 | 0); |
| 11184 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11185 | |
| 11186 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11187 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11188 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11189 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11190 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 11191 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11192 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11193 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11194 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11195 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11196 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11197 | TestCompletionCallback callback; |
| 11198 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11199 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11200 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11201 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11202 | } |
| 11203 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11204 | // Regression test for https://crbug.com/615497: |
| 11205 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11206 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11207 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11208 | HttpRequestInfo request; |
| 11209 | request.method = "GET"; |
| 11210 | request.url = GURL("http://www.example.org/"); |
| 11211 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11212 | request.traffic_annotation = |
| 11213 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11214 | |
| 11215 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11216 | StaticSocketDataProvider first_data; |
| 11217 | first_data.set_connect_data(mock_connect); |
| 11218 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 11219 | |
| 11220 | MockRead data_reads[] = { |
| 11221 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11222 | MockRead(ASYNC, OK), |
| 11223 | }; |
| 11224 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 11225 | 0); |
| 11226 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11227 | |
| 11228 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11229 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11230 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11231 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11232 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11233 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11234 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11235 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11236 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11237 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11238 | TestCompletionCallback callback; |
| 11239 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11240 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11241 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11242 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11243 | } |
| 11244 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11245 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11246 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11247 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11248 | HttpServerProperties* http_server_properties = |
| 11249 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11250 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11251 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11252 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11253 | http_server_properties->SetQuicAlternativeService( |
| 11254 | test_server, alternative_service, expiration, |
| 11255 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11256 | EXPECT_EQ( |
| 11257 | 1u, |
| 11258 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11259 | |
| 11260 | // Send a clear header. |
| 11261 | MockRead data_reads[] = { |
| 11262 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11263 | MockRead("Alt-Svc: clear\r\n"), |
| 11264 | MockRead("\r\n"), |
| 11265 | MockRead("hello world"), |
| 11266 | MockRead(SYNCHRONOUS, OK), |
| 11267 | }; |
| 11268 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 11269 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11270 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11271 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11272 | ssl.ssl_info.cert = |
| 11273 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11274 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11276 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11277 | HttpRequestInfo request; |
| 11278 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11279 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11280 | request.traffic_annotation = |
| 11281 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11282 | |
| 11283 | TestCompletionCallback callback; |
| 11284 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11285 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11286 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11287 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11288 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11289 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11290 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11291 | ASSERT_TRUE(response); |
| 11292 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11293 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11294 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11295 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11296 | |
| 11297 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11298 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11299 | EXPECT_EQ("hello world", response_data); |
| 11300 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11301 | EXPECT_TRUE( |
| 11302 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11303 | } |
| 11304 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11305 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11306 | MockRead data_reads[] = { |
| 11307 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11308 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 11309 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11310 | MockRead("hello world"), |
| 11311 | MockRead(SYNCHRONOUS, OK), |
| 11312 | }; |
| 11313 | |
| 11314 | HttpRequestInfo request; |
| 11315 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11316 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11317 | request.traffic_annotation = |
| 11318 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11319 | |
| 11320 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11321 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11322 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11323 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11324 | ssl.ssl_info.cert = |
| 11325 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11326 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11327 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11328 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11329 | TestCompletionCallback callback; |
| 11330 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11331 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11332 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11333 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11334 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11335 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11336 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11337 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11338 | HttpServerProperties* http_server_properties = |
| 11339 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11340 | EXPECT_TRUE( |
| 11341 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11342 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11343 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11344 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11345 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11346 | ASSERT_TRUE(response); |
| 11347 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11348 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11349 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11350 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11351 | |
| 11352 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11353 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11354 | EXPECT_EQ("hello world", response_data); |
| 11355 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11356 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11357 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11358 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 11359 | |
| 11360 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 11361 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11362 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11363 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 11364 | 1234); |
| 11365 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11366 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11367 | } |
| 11368 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11369 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11370 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11371 | HostPortPair alternative("alternative.example.org", 443); |
| 11372 | std::string origin_url = "https://origin.example.org:443"; |
| 11373 | std::string alternative_url = "https://alternative.example.org:443"; |
| 11374 | |
| 11375 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 11376 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11377 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11378 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11379 | |
| 11380 | // HTTP/1.1 data for request. |
| 11381 | MockWrite http_writes[] = { |
| 11382 | MockWrite("GET / HTTP/1.1\r\n" |
| 11383 | "Host: alternative.example.org\r\n" |
| 11384 | "Connection: keep-alive\r\n\r\n"), |
| 11385 | }; |
| 11386 | |
| 11387 | MockRead http_reads[] = { |
| 11388 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11389 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11390 | "Content-Length: 40\r\n\r\n" |
| 11391 | "first HTTP/1.1 response from alternative"), |
| 11392 | }; |
| 11393 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11394 | http_writes, arraysize(http_writes)); |
| 11395 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11396 | |
| 11397 | StaticSocketDataProvider data_refused; |
| 11398 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11399 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11400 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11401 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11402 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11403 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11404 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11405 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11406 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11407 | http_server_properties->SetQuicAlternativeService( |
| 11408 | server, alternative_service, expiration, |
| 11409 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11410 | // Mark the QUIC alternative service as broken. |
| 11411 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 11412 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11413 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11414 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11415 | request.method = "GET"; |
| 11416 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11417 | request.traffic_annotation = |
| 11418 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11419 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11420 | TestCompletionCallback callback; |
| 11421 | NetErrorDetails details; |
| 11422 | EXPECT_FALSE(details.quic_broken); |
| 11423 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11424 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11425 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11426 | EXPECT_TRUE(details.quic_broken); |
| 11427 | } |
| 11428 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11429 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11430 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11431 | HostPortPair alternative1("alternative1.example.org", 443); |
| 11432 | HostPortPair alternative2("alternative2.example.org", 443); |
| 11433 | std::string origin_url = "https://origin.example.org:443"; |
| 11434 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 11435 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 11436 | |
| 11437 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 11438 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11439 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11440 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11441 | |
| 11442 | // HTTP/1.1 data for request. |
| 11443 | MockWrite http_writes[] = { |
| 11444 | MockWrite("GET / HTTP/1.1\r\n" |
| 11445 | "Host: alternative1.example.org\r\n" |
| 11446 | "Connection: keep-alive\r\n\r\n"), |
| 11447 | }; |
| 11448 | |
| 11449 | MockRead http_reads[] = { |
| 11450 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11451 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11452 | "Content-Length: 40\r\n\r\n" |
| 11453 | "first HTTP/1.1 response from alternative1"), |
| 11454 | }; |
| 11455 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11456 | http_writes, arraysize(http_writes)); |
| 11457 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11458 | |
| 11459 | StaticSocketDataProvider data_refused; |
| 11460 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11461 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11462 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11463 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11464 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11465 | session->http_server_properties(); |
| 11466 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11467 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11468 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 11469 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11470 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11471 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11472 | alternative_service_info_vector.push_back( |
| 11473 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11474 | alternative_service1, expiration, |
| 11475 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11476 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11477 | alternative_service_info_vector.push_back( |
| 11478 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11479 | alternative_service2, expiration, |
| 11480 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11481 | |
| 11482 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11483 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11484 | |
| 11485 | // Mark one of the QUIC alternative service as broken. |
| 11486 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11487 | EXPECT_EQ(2u, |
| 11488 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11489 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11490 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11491 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11492 | request.method = "GET"; |
| 11493 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11494 | request.traffic_annotation = |
| 11495 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11496 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11497 | TestCompletionCallback callback; |
| 11498 | NetErrorDetails details; |
| 11499 | EXPECT_FALSE(details.quic_broken); |
| 11500 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11501 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11502 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11503 | EXPECT_FALSE(details.quic_broken); |
| 11504 | } |
| 11505 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11506 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11507 | HttpRequestInfo request; |
| 11508 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11509 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11510 | request.traffic_annotation = |
| 11511 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11512 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11513 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11514 | StaticSocketDataProvider first_data; |
| 11515 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11516 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11517 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11518 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11519 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11520 | |
| 11521 | MockRead data_reads[] = { |
| 11522 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11523 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11524 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11525 | }; |
| 11526 | StaticSocketDataProvider second_data( |
| 11527 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11528 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11529 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11530 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11531 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11532 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11533 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11534 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11535 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 11536 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11537 | // Port is ignored by MockConnect anyway. |
| 11538 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11539 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11540 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11541 | http_server_properties->SetHttp2AlternativeService( |
| 11542 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11543 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11544 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11545 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11546 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11547 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11548 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11549 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11551 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11552 | ASSERT_TRUE(response); |
| 11553 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11554 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11555 | |
| 11556 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11557 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11558 | EXPECT_EQ("hello world", response_data); |
| 11559 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11560 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 11561 | http_server_properties->GetAlternativeServiceInfos(server); |
| 11562 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11563 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11564 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11565 | EXPECT_TRUE( |
| 11566 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11567 | } |
| 11568 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11569 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11570 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11571 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11572 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11573 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11574 | HttpRequestInfo restricted_port_request; |
| 11575 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11576 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11577 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11578 | restricted_port_request.traffic_annotation = |
| 11579 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11580 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11581 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11582 | StaticSocketDataProvider first_data; |
| 11583 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11584 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11585 | |
| 11586 | MockRead data_reads[] = { |
| 11587 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11588 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11589 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11590 | }; |
| 11591 | StaticSocketDataProvider second_data( |
| 11592 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11593 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11594 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11595 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11596 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11597 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11598 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11599 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11600 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11601 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11602 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11603 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11604 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11605 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11606 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11607 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11608 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11609 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11610 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11611 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11612 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11613 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11614 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11615 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11616 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11617 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11618 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11619 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11620 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 11621 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 11622 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11623 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11624 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11625 | |
| 11626 | HttpRequestInfo restricted_port_request; |
| 11627 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11628 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11629 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11630 | restricted_port_request.traffic_annotation = |
| 11631 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11632 | |
| 11633 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11634 | StaticSocketDataProvider first_data; |
| 11635 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11636 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11637 | |
| 11638 | MockRead data_reads[] = { |
| 11639 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11640 | MockRead("hello world"), |
| 11641 | MockRead(ASYNC, OK), |
| 11642 | }; |
| 11643 | StaticSocketDataProvider second_data( |
| 11644 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11645 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11646 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11647 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11648 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11649 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11650 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11651 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11652 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11653 | session->http_server_properties(); |
| 11654 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11655 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11656 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11657 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11658 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11659 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11660 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11661 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11662 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11663 | TestCompletionCallback callback; |
| 11664 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11665 | EXPECT_EQ(ERR_IO_PENDING, |
| 11666 | trans.Start(&restricted_port_request, callback.callback(), |
| 11667 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11668 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11669 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11670 | } |
| 11671 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11672 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11673 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11674 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11675 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11676 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11677 | HttpRequestInfo restricted_port_request; |
| 11678 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11679 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11680 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11681 | restricted_port_request.traffic_annotation = |
| 11682 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11683 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11684 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11685 | StaticSocketDataProvider first_data; |
| 11686 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11687 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11688 | |
| 11689 | MockRead data_reads[] = { |
| 11690 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11691 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11692 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11693 | }; |
| 11694 | StaticSocketDataProvider second_data( |
| 11695 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11696 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11697 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11698 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11699 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11700 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11701 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11702 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11703 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11704 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11705 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11706 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11707 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11708 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11709 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11710 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11711 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11712 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11713 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11714 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11715 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11716 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11717 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11719 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11720 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11721 | } |
| 11722 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11723 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11724 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11725 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11726 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11727 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11728 | HttpRequestInfo unrestricted_port_request; |
| 11729 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11730 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11731 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11732 | unrestricted_port_request.traffic_annotation = |
| 11733 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11734 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11735 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11736 | StaticSocketDataProvider first_data; |
| 11737 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11738 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11739 | |
| 11740 | MockRead data_reads[] = { |
| 11741 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11742 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11743 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11744 | }; |
| 11745 | StaticSocketDataProvider second_data( |
| 11746 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11747 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11748 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11749 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11750 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11751 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11753 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11754 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11755 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11756 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11757 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11758 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11759 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11760 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11761 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11762 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11763 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11764 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11765 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11767 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11768 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11769 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11770 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11771 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11772 | } |
| 11773 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11774 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11775 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11776 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11777 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11778 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11779 | HttpRequestInfo unrestricted_port_request; |
| 11780 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11781 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11782 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11783 | unrestricted_port_request.traffic_annotation = |
| 11784 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11785 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11786 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11787 | StaticSocketDataProvider first_data; |
| 11788 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11789 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11790 | |
| 11791 | MockRead data_reads[] = { |
| 11792 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11793 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11794 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11795 | }; |
| 11796 | StaticSocketDataProvider second_data( |
| 11797 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11798 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11799 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11800 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11801 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11802 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11803 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11804 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11805 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11806 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11807 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11808 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11809 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11810 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11811 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11812 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11813 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11814 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11815 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11816 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11817 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11818 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11819 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11821 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11822 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11823 | } |
| 11824 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11825 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11826 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 11827 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11828 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11829 | HttpRequestInfo request; |
| 11830 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11831 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11832 | request.traffic_annotation = |
| 11833 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11834 | |
| 11835 | // The alternate protocol request will error out before we attempt to connect, |
| 11836 | // so only the standard HTTP request will try to connect. |
| 11837 | MockRead data_reads[] = { |
| 11838 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11839 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11840 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11841 | }; |
| 11842 | StaticSocketDataProvider data( |
| 11843 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11844 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11845 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11846 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11847 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11848 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11849 | session->http_server_properties(); |
| 11850 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11851 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11852 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11853 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11854 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11855 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11856 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11857 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11858 | TestCompletionCallback callback; |
| 11859 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11860 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11861 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11862 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11863 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11864 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11865 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11866 | ASSERT_TRUE(response); |
| 11867 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11868 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11869 | |
| 11870 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11871 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11872 | EXPECT_EQ("hello world", response_data); |
| 11873 | } |
| 11874 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11875 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11876 | HttpRequestInfo request; |
| 11877 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11878 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11879 | request.traffic_annotation = |
| 11880 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11881 | |
| 11882 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11883 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11884 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11885 | MockRead("\r\n"), |
| 11886 | MockRead("hello world"), |
| 11887 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11888 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11889 | |
| 11890 | StaticSocketDataProvider first_transaction( |
| 11891 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11892 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11893 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11894 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11895 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11896 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11897 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11898 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11899 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11900 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11901 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11902 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11903 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11904 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11905 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11906 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11907 | }; |
| 11908 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11909 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11910 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11911 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11912 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11913 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11914 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11915 | NULL, 0, NULL, 0); |
| 11916 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11917 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11918 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11919 | &hanging_non_alternate_protocol_socket); |
| 11920 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11921 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11922 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11923 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11924 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11925 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11926 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11927 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11928 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11929 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11930 | |
| 11931 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11932 | ASSERT_TRUE(response); |
| 11933 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11934 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11935 | |
| 11936 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11937 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11938 | EXPECT_EQ("hello world", response_data); |
| 11939 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11940 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11941 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11942 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11943 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11944 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11945 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11946 | |
| 11947 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11948 | ASSERT_TRUE(response); |
| 11949 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11950 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11951 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11952 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11953 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11954 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11955 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11956 | } |
| 11957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11958 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11959 | HttpRequestInfo request; |
| 11960 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11961 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11962 | request.traffic_annotation = |
| 11963 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11964 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11965 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11966 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11967 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11968 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11969 | MockRead("\r\n"), |
| 11970 | MockRead("hello world"), |
| 11971 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11972 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11973 | }; |
| 11974 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11975 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 11976 | 0); |
| 11977 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11978 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11979 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11980 | ssl_http11.ssl_info.cert = |
| 11981 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11982 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11983 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11984 | |
| 11985 | // Second transaction starts an alternative and a non-alternative Job. |
| 11986 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11987 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11988 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 11989 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11990 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11991 | |
| 11992 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 11993 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11994 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11995 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11996 | // Third transaction starts an alternative and a non-alternative job. |
| 11997 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11998 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11999 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12000 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12001 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12002 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12003 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12004 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12005 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12006 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12007 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12008 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12009 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12010 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12011 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12012 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12013 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12014 | }; |
| 12015 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12016 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12017 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12018 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12019 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12020 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12021 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12022 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 12023 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12024 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12025 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12026 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12027 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12028 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12029 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12030 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12031 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12032 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12033 | |
| 12034 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12035 | ASSERT_TRUE(response); |
| 12036 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12037 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12038 | |
| 12039 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12040 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12041 | EXPECT_EQ("hello world", response_data); |
| 12042 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12043 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12044 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12045 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12047 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12048 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12049 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12050 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12051 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12052 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12053 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12054 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12055 | |
| 12056 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12057 | ASSERT_TRUE(response); |
| 12058 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12059 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12060 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12061 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12062 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12063 | EXPECT_EQ("hello!", response_data); |
| 12064 | |
| 12065 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12066 | ASSERT_TRUE(response); |
| 12067 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12068 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12069 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12070 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12071 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12072 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12073 | } |
| 12074 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12075 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12076 | HttpRequestInfo request; |
| 12077 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12078 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12079 | request.traffic_annotation = |
| 12080 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12081 | |
| 12082 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12083 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12084 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12085 | MockRead("\r\n"), |
| 12086 | MockRead("hello world"), |
| 12087 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12088 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12089 | }; |
| 12090 | |
| 12091 | StaticSocketDataProvider first_transaction( |
| 12092 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12093 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12094 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12095 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12096 | ssl.ssl_info.cert = |
| 12097 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12098 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12099 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12100 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12101 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12102 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 12103 | NULL, 0, NULL, 0); |
| 12104 | hanging_alternate_protocol_socket.set_connect_data( |
| 12105 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12106 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12107 | &hanging_alternate_protocol_socket); |
| 12108 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12109 | // 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] | 12110 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 12111 | NULL, 0); |
| 12112 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12113 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12115 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12116 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12117 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12118 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12119 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12120 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12121 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12122 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12123 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12124 | |
| 12125 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12126 | ASSERT_TRUE(response); |
| 12127 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12128 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12129 | |
| 12130 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12131 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12132 | EXPECT_EQ("hello world", response_data); |
| 12133 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12134 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12135 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12136 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12137 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12138 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12139 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12140 | |
| 12141 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12142 | ASSERT_TRUE(response); |
| 12143 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12144 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12145 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12146 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12147 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12148 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12149 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12150 | } |
| 12151 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12152 | class CapturingProxyResolver : public ProxyResolver { |
| 12153 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 12154 | CapturingProxyResolver() = default; |
| 12155 | ~CapturingProxyResolver() override = default; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12156 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12157 | int GetProxyForURL(const GURL& url, |
| 12158 | ProxyInfo* results, |
| 12159 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 12160 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12161 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 12162 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 12163 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12164 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12165 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12166 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12167 | } |
| 12168 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 12169 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 12170 | |
| 12171 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12172 | std::vector<GURL> resolved_; |
| 12173 | |
| 12174 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 12175 | }; |
| 12176 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12177 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 12178 | public: |
| 12179 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 12180 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 12181 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 12182 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 12183 | std::unique_ptr<ProxyResolver>* resolver, |
| 12184 | const net::CompletionCallback& callback, |
| 12185 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12186 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12187 | return OK; |
| 12188 | } |
| 12189 | |
| 12190 | private: |
| 12191 | ProxyResolver* resolver_; |
| 12192 | }; |
| 12193 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12194 | // Test that proxy is resolved using the origin url, |
| 12195 | // regardless of the alternative server. |
| 12196 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 12197 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 12198 | ProxyConfig proxy_config; |
| 12199 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 12200 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12201 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 12202 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12203 | |
| 12204 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12205 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12206 | &capturing_proxy_resolver); |
| 12207 | |
| 12208 | TestNetLog net_log; |
| 12209 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12210 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12211 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 12212 | &net_log); |
| 12213 | |
| 12214 | session_deps_.net_log = &net_log; |
| 12215 | |
| 12216 | // Configure alternative service with a hostname that is not bypassed by the |
| 12217 | // proxy. |
| 12218 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12219 | HttpServerProperties* http_server_properties = |
| 12220 | session->http_server_properties(); |
| 12221 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 12222 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12223 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12224 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12225 | http_server_properties->SetHttp2AlternativeService( |
| 12226 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12227 | |
| 12228 | // Non-alternative job should hang. |
| 12229 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 12230 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 12231 | nullptr, 0); |
| 12232 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 12233 | session_deps_.socket_factory->AddSocketDataProvider( |
| 12234 | &hanging_alternate_protocol_socket); |
| 12235 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12236 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12237 | |
| 12238 | HttpRequestInfo request; |
| 12239 | request.method = "GET"; |
| 12240 | request.url = GURL("https://www.example.org/"); |
| 12241 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12242 | request.traffic_annotation = |
| 12243 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12244 | |
| 12245 | SpdySerializedFrame req( |
| 12246 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 12247 | |
| 12248 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 12249 | |
| 12250 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 12251 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 12252 | MockRead spdy_reads[] = { |
| 12253 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 12254 | }; |
| 12255 | |
| 12256 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12257 | arraysize(spdy_writes)); |
| 12258 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 12259 | |
| 12260 | TestCompletionCallback callback; |
| 12261 | |
| 12262 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12263 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12264 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12265 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 12266 | |
| 12267 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12268 | ASSERT_TRUE(response); |
| 12269 | ASSERT_TRUE(response->headers); |
| 12270 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 12271 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12272 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12273 | |
| 12274 | std::string response_data; |
| 12275 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12276 | EXPECT_EQ("hello!", response_data); |
| 12277 | |
| 12278 | // Origin host bypasses proxy, no resolution should have happened. |
| 12279 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 12280 | } |
| 12281 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12282 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12283 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12284 | proxy_config.set_auto_detect(true); |
| 12285 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 12286 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12287 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12288 | session_deps_.proxy_resolution_service = |
| 12289 | std::make_unique<ProxyResolutionService>( |
| 12290 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 12291 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 12292 | std::make_unique<CapturingProxyResolverFactory>( |
| 12293 | &capturing_proxy_resolver), |
| 12294 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12295 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12296 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12297 | |
| 12298 | HttpRequestInfo request; |
| 12299 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12300 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12301 | request.traffic_annotation = |
| 12302 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12303 | |
| 12304 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12305 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12306 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12307 | MockRead("\r\n"), |
| 12308 | MockRead("hello world"), |
| 12309 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12310 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12311 | }; |
| 12312 | |
| 12313 | StaticSocketDataProvider first_transaction( |
| 12314 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12315 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12316 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12317 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12318 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12319 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12320 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12321 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12322 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12323 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12324 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12325 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12326 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12327 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12328 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12329 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12330 | }; |
| 12331 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12332 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 12333 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12334 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12335 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12336 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12337 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 12338 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12339 | }; |
| 12340 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12341 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12342 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12343 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12344 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12345 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12346 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 12347 | NULL, 0, NULL, 0); |
| 12348 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12349 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12350 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12351 | &hanging_non_alternate_protocol_socket); |
| 12352 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12353 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12354 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12355 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12356 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12357 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12358 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12359 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12361 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12362 | |
| 12363 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12364 | ASSERT_TRUE(response); |
| 12365 | ASSERT_TRUE(response->headers); |
| 12366 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 12367 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12368 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12369 | |
| 12370 | std::string response_data; |
| 12371 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 12372 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12373 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12374 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12375 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12376 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12377 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12378 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12379 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12380 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12381 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12382 | ASSERT_TRUE(response); |
| 12383 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12384 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12385 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12386 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12387 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12388 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12389 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12390 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 12391 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12392 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12393 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12394 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12395 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12396 | LoadTimingInfo load_timing_info; |
| 12397 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12398 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12399 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12400 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12401 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12402 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12403 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12404 | HttpRequestInfo request; |
| 12405 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12406 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12407 | request.traffic_annotation = |
| 12408 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12409 | |
| 12410 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12411 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12412 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12413 | MockRead("\r\n"), |
| 12414 | MockRead("hello world"), |
| 12415 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12416 | }; |
| 12417 | |
| 12418 | StaticSocketDataProvider first_transaction( |
| 12419 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12420 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12421 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12422 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12424 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12425 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12426 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12427 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12428 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12429 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12430 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12431 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12432 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12433 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12434 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12435 | }; |
| 12436 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12437 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12438 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12439 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12440 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 12441 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12442 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12443 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12444 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12445 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12446 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12447 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12448 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12449 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12450 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12451 | |
| 12452 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12453 | ASSERT_TRUE(response); |
| 12454 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12455 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12456 | |
| 12457 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12458 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12459 | EXPECT_EQ("hello world", response_data); |
| 12460 | |
| 12461 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12462 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12463 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 12464 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12465 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 12466 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 12467 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12468 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12469 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12470 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12471 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12472 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12473 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12474 | |
| 12475 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12476 | ASSERT_TRUE(response); |
| 12477 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12478 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12479 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12480 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12481 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12482 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12483 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12484 | } |
| 12485 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12486 | // GenerateAuthToken is a mighty big test. |
| 12487 | // It tests all permutation of GenerateAuthToken behavior: |
| 12488 | // - Synchronous and Asynchronous completion. |
| 12489 | // - OK or error on completion. |
| 12490 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 12491 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 12492 | // - Non-authenticating and authenticating backend. |
| 12493 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12494 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12495 | // problems generating an auth token for an authenticating proxy, we don't |
| 12496 | // need to test all permutations of the backend server). |
| 12497 | // |
| 12498 | // The test proceeds by going over each of the configuration cases, and |
| 12499 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 12500 | // specifies both the configuration for the test as well as the expectations |
| 12501 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12502 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12503 | static const char kServer[] = "http://www.example.com"; |
| 12504 | static const char kSecureServer[] = "https://www.example.com"; |
| 12505 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12506 | |
| 12507 | enum AuthTiming { |
| 12508 | AUTH_NONE, |
| 12509 | AUTH_SYNC, |
| 12510 | AUTH_ASYNC, |
| 12511 | }; |
| 12512 | |
| 12513 | const MockWrite kGet( |
| 12514 | "GET / HTTP/1.1\r\n" |
| 12515 | "Host: www.example.com\r\n" |
| 12516 | "Connection: keep-alive\r\n\r\n"); |
| 12517 | const MockWrite kGetProxy( |
| 12518 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12519 | "Host: www.example.com\r\n" |
| 12520 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12521 | const MockWrite kGetAuth( |
| 12522 | "GET / HTTP/1.1\r\n" |
| 12523 | "Host: www.example.com\r\n" |
| 12524 | "Connection: keep-alive\r\n" |
| 12525 | "Authorization: auth_token\r\n\r\n"); |
| 12526 | const MockWrite kGetProxyAuth( |
| 12527 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12528 | "Host: www.example.com\r\n" |
| 12529 | "Proxy-Connection: keep-alive\r\n" |
| 12530 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12531 | const MockWrite kGetAuthThroughProxy( |
| 12532 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12533 | "Host: www.example.com\r\n" |
| 12534 | "Proxy-Connection: keep-alive\r\n" |
| 12535 | "Authorization: auth_token\r\n\r\n"); |
| 12536 | const MockWrite kGetAuthWithProxyAuth( |
| 12537 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12538 | "Host: www.example.com\r\n" |
| 12539 | "Proxy-Connection: keep-alive\r\n" |
| 12540 | "Proxy-Authorization: auth_token\r\n" |
| 12541 | "Authorization: auth_token\r\n\r\n"); |
| 12542 | const MockWrite kConnect( |
| 12543 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12544 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12545 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12546 | const MockWrite kConnectProxyAuth( |
| 12547 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12548 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12549 | "Proxy-Connection: keep-alive\r\n" |
| 12550 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12551 | |
| 12552 | const MockRead kSuccess( |
| 12553 | "HTTP/1.1 200 OK\r\n" |
| 12554 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12555 | "Content-Length: 3\r\n\r\n" |
| 12556 | "Yes"); |
| 12557 | const MockRead kFailure( |
| 12558 | "Should not be called."); |
| 12559 | const MockRead kServerChallenge( |
| 12560 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12561 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12562 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12563 | "Content-Length: 14\r\n\r\n" |
| 12564 | "Unauthorized\r\n"); |
| 12565 | const MockRead kProxyChallenge( |
| 12566 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12567 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 12568 | "Proxy-Connection: close\r\n" |
| 12569 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12570 | "Content-Length: 14\r\n\r\n" |
| 12571 | "Unauthorized\r\n"); |
| 12572 | const MockRead kProxyConnected( |
| 12573 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 12574 | |
| 12575 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 12576 | // no constructors, but the C++ compiler on Windows warns about |
| 12577 | // unspecified data in compound literals. So, moved to using constructors, |
| 12578 | // and TestRound's created with the default constructor should not be used. |
| 12579 | struct TestRound { |
| 12580 | TestRound() |
| 12581 | : expected_rv(ERR_UNEXPECTED), |
| 12582 | extra_write(NULL), |
| 12583 | extra_read(NULL) { |
| 12584 | } |
| 12585 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12586 | int expected_rv_arg) |
| 12587 | : write(write_arg), |
| 12588 | read(read_arg), |
| 12589 | expected_rv(expected_rv_arg), |
| 12590 | extra_write(NULL), |
| 12591 | extra_read(NULL) { |
| 12592 | } |
| 12593 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12594 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 12595 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12596 | : write(write_arg), |
| 12597 | read(read_arg), |
| 12598 | expected_rv(expected_rv_arg), |
| 12599 | extra_write(extra_write_arg), |
| 12600 | extra_read(extra_read_arg) { |
| 12601 | } |
| 12602 | MockWrite write; |
| 12603 | MockRead read; |
| 12604 | int expected_rv; |
| 12605 | const MockWrite* extra_write; |
| 12606 | const MockRead* extra_read; |
| 12607 | }; |
| 12608 | |
| 12609 | static const int kNoSSL = 500; |
| 12610 | |
| 12611 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12612 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12613 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12614 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12615 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12616 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12617 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12618 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12619 | int num_auth_rounds; |
| 12620 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12621 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12622 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12623 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12624 | {__LINE__, |
| 12625 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12626 | AUTH_NONE, |
| 12627 | OK, |
| 12628 | kServer, |
| 12629 | AUTH_NONE, |
| 12630 | OK, |
| 12631 | 1, |
| 12632 | kNoSSL, |
| 12633 | {TestRound(kGet, kSuccess, OK)}}, |
| 12634 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12635 | {__LINE__, |
| 12636 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12637 | AUTH_NONE, |
| 12638 | OK, |
| 12639 | kServer, |
| 12640 | AUTH_SYNC, |
| 12641 | OK, |
| 12642 | 2, |
| 12643 | kNoSSL, |
| 12644 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12645 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12646 | {__LINE__, |
| 12647 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12648 | AUTH_NONE, |
| 12649 | OK, |
| 12650 | kServer, |
| 12651 | AUTH_SYNC, |
| 12652 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12653 | 3, |
| 12654 | kNoSSL, |
| 12655 | {TestRound(kGet, kServerChallenge, OK), |
| 12656 | TestRound(kGet, kServerChallenge, OK), |
| 12657 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12658 | {__LINE__, |
| 12659 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12660 | AUTH_NONE, |
| 12661 | OK, |
| 12662 | kServer, |
| 12663 | AUTH_SYNC, |
| 12664 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12665 | 2, |
| 12666 | kNoSSL, |
| 12667 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12668 | {__LINE__, |
| 12669 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12670 | AUTH_NONE, |
| 12671 | OK, |
| 12672 | kServer, |
| 12673 | AUTH_SYNC, |
| 12674 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 12675 | 2, |
| 12676 | kNoSSL, |
| 12677 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12678 | {__LINE__, |
| 12679 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12680 | AUTH_SYNC, |
| 12681 | ERR_FAILED, |
| 12682 | kServer, |
| 12683 | AUTH_NONE, |
| 12684 | OK, |
| 12685 | 2, |
| 12686 | kNoSSL, |
| 12687 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12688 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12689 | {__LINE__, |
| 12690 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12691 | AUTH_ASYNC, |
| 12692 | ERR_FAILED, |
| 12693 | kServer, |
| 12694 | AUTH_NONE, |
| 12695 | OK, |
| 12696 | 2, |
| 12697 | kNoSSL, |
| 12698 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12699 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12700 | {__LINE__, |
| 12701 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12702 | AUTH_NONE, |
| 12703 | OK, |
| 12704 | kServer, |
| 12705 | AUTH_SYNC, |
| 12706 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12707 | 2, |
| 12708 | kNoSSL, |
| 12709 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12710 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12711 | {__LINE__, |
| 12712 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12713 | AUTH_NONE, |
| 12714 | OK, |
| 12715 | kServer, |
| 12716 | AUTH_ASYNC, |
| 12717 | ERR_FAILED, |
| 12718 | 2, |
| 12719 | kNoSSL, |
| 12720 | {TestRound(kGet, kServerChallenge, OK), |
| 12721 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12722 | {__LINE__, |
| 12723 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12724 | AUTH_NONE, |
| 12725 | OK, |
| 12726 | kServer, |
| 12727 | AUTH_ASYNC, |
| 12728 | OK, |
| 12729 | 2, |
| 12730 | kNoSSL, |
| 12731 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12732 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12733 | {__LINE__, |
| 12734 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12735 | AUTH_NONE, |
| 12736 | OK, |
| 12737 | kServer, |
| 12738 | AUTH_ASYNC, |
| 12739 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12740 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12741 | kNoSSL, |
| 12742 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12743 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12744 | TestRound(kGet, kServerChallenge, OK), |
| 12745 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12746 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12747 | {__LINE__, |
| 12748 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12749 | AUTH_NONE, |
| 12750 | OK, |
| 12751 | kServer, |
| 12752 | AUTH_NONE, |
| 12753 | OK, |
| 12754 | 1, |
| 12755 | kNoSSL, |
| 12756 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12757 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12758 | {__LINE__, |
| 12759 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12760 | AUTH_NONE, |
| 12761 | OK, |
| 12762 | kServer, |
| 12763 | AUTH_SYNC, |
| 12764 | OK, |
| 12765 | 2, |
| 12766 | kNoSSL, |
| 12767 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12768 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12769 | {__LINE__, |
| 12770 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12771 | AUTH_NONE, |
| 12772 | OK, |
| 12773 | kServer, |
| 12774 | AUTH_SYNC, |
| 12775 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12776 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12777 | kNoSSL, |
| 12778 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12779 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12780 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12781 | {__LINE__, |
| 12782 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12783 | AUTH_NONE, |
| 12784 | OK, |
| 12785 | kServer, |
| 12786 | AUTH_ASYNC, |
| 12787 | OK, |
| 12788 | 2, |
| 12789 | kNoSSL, |
| 12790 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12791 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12792 | {__LINE__, |
| 12793 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12794 | AUTH_NONE, |
| 12795 | OK, |
| 12796 | kServer, |
| 12797 | AUTH_ASYNC, |
| 12798 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12799 | 2, |
| 12800 | kNoSSL, |
| 12801 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12802 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12803 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12804 | {__LINE__, |
| 12805 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12806 | AUTH_SYNC, |
| 12807 | OK, |
| 12808 | kServer, |
| 12809 | AUTH_NONE, |
| 12810 | OK, |
| 12811 | 2, |
| 12812 | kNoSSL, |
| 12813 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12814 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12815 | {__LINE__, |
| 12816 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12817 | AUTH_SYNC, |
| 12818 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12819 | kServer, |
| 12820 | AUTH_NONE, |
| 12821 | OK, |
| 12822 | 2, |
| 12823 | kNoSSL, |
| 12824 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12825 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12826 | {__LINE__, |
| 12827 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12828 | AUTH_ASYNC, |
| 12829 | OK, |
| 12830 | kServer, |
| 12831 | AUTH_NONE, |
| 12832 | OK, |
| 12833 | 2, |
| 12834 | kNoSSL, |
| 12835 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12836 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12837 | {__LINE__, |
| 12838 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12839 | AUTH_ASYNC, |
| 12840 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12841 | kServer, |
| 12842 | AUTH_NONE, |
| 12843 | OK, |
| 12844 | 2, |
| 12845 | kNoSSL, |
| 12846 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12847 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12848 | {__LINE__, |
| 12849 | kProxy, |
| 12850 | AUTH_ASYNC, |
| 12851 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12852 | kServer, |
| 12853 | AUTH_NONE, |
| 12854 | OK, |
| 12855 | 3, |
| 12856 | kNoSSL, |
| 12857 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12858 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12859 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12860 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12861 | {__LINE__, |
| 12862 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12863 | AUTH_SYNC, |
| 12864 | OK, |
| 12865 | kServer, |
| 12866 | AUTH_SYNC, |
| 12867 | OK, |
| 12868 | 3, |
| 12869 | kNoSSL, |
| 12870 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12871 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12872 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12873 | {__LINE__, |
| 12874 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12875 | AUTH_SYNC, |
| 12876 | OK, |
| 12877 | kServer, |
| 12878 | AUTH_SYNC, |
| 12879 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12880 | 3, |
| 12881 | kNoSSL, |
| 12882 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12883 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12884 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12885 | {__LINE__, |
| 12886 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12887 | AUTH_ASYNC, |
| 12888 | OK, |
| 12889 | kServer, |
| 12890 | AUTH_SYNC, |
| 12891 | OK, |
| 12892 | 3, |
| 12893 | kNoSSL, |
| 12894 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12895 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12896 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12897 | {__LINE__, |
| 12898 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12899 | AUTH_ASYNC, |
| 12900 | OK, |
| 12901 | kServer, |
| 12902 | AUTH_SYNC, |
| 12903 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12904 | 3, |
| 12905 | kNoSSL, |
| 12906 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12907 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [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_SYNC, |
| 12912 | OK, |
| 12913 | kServer, |
| 12914 | AUTH_ASYNC, |
| 12915 | OK, |
| 12916 | 3, |
| 12917 | kNoSSL, |
| 12918 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12919 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12920 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12921 | {__LINE__, |
| 12922 | kProxy, |
| 12923 | AUTH_SYNC, |
| 12924 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12925 | kServer, |
| 12926 | AUTH_ASYNC, |
| 12927 | OK, |
| 12928 | 4, |
| 12929 | kNoSSL, |
| 12930 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12931 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12932 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12933 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12934 | {__LINE__, |
| 12935 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12936 | AUTH_SYNC, |
| 12937 | OK, |
| 12938 | kServer, |
| 12939 | AUTH_ASYNC, |
| 12940 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12941 | 3, |
| 12942 | kNoSSL, |
| 12943 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12944 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12945 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12946 | {__LINE__, |
| 12947 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12948 | AUTH_ASYNC, |
| 12949 | OK, |
| 12950 | kServer, |
| 12951 | AUTH_ASYNC, |
| 12952 | OK, |
| 12953 | 3, |
| 12954 | kNoSSL, |
| 12955 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12956 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12957 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12958 | {__LINE__, |
| 12959 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12960 | AUTH_ASYNC, |
| 12961 | OK, |
| 12962 | kServer, |
| 12963 | AUTH_ASYNC, |
| 12964 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12965 | 3, |
| 12966 | kNoSSL, |
| 12967 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12968 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12969 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12970 | {__LINE__, |
| 12971 | kProxy, |
| 12972 | AUTH_ASYNC, |
| 12973 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12974 | kServer, |
| 12975 | AUTH_ASYNC, |
| 12976 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12977 | 4, |
| 12978 | kNoSSL, |
| 12979 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12980 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12981 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12982 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12983 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12984 | {__LINE__, |
| 12985 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12986 | AUTH_NONE, |
| 12987 | OK, |
| 12988 | kSecureServer, |
| 12989 | AUTH_NONE, |
| 12990 | OK, |
| 12991 | 1, |
| 12992 | 0, |
| 12993 | {TestRound(kGet, kSuccess, OK)}}, |
| 12994 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12995 | {__LINE__, |
| 12996 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12997 | AUTH_NONE, |
| 12998 | OK, |
| 12999 | kSecureServer, |
| 13000 | AUTH_SYNC, |
| 13001 | OK, |
| 13002 | 2, |
| 13003 | 0, |
| 13004 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13005 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13006 | {__LINE__, |
| 13007 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13008 | AUTH_NONE, |
| 13009 | OK, |
| 13010 | kSecureServer, |
| 13011 | AUTH_SYNC, |
| 13012 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13013 | 2, |
| 13014 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13015 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13016 | {__LINE__, |
| 13017 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13018 | AUTH_NONE, |
| 13019 | OK, |
| 13020 | kSecureServer, |
| 13021 | AUTH_ASYNC, |
| 13022 | OK, |
| 13023 | 2, |
| 13024 | 0, |
| 13025 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13026 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13027 | {__LINE__, |
| 13028 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13029 | AUTH_NONE, |
| 13030 | OK, |
| 13031 | kSecureServer, |
| 13032 | AUTH_ASYNC, |
| 13033 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13034 | 2, |
| 13035 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13036 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13037 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13038 | {__LINE__, |
| 13039 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13040 | AUTH_NONE, |
| 13041 | OK, |
| 13042 | kSecureServer, |
| 13043 | AUTH_NONE, |
| 13044 | OK, |
| 13045 | 1, |
| 13046 | 0, |
| 13047 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13048 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13049 | {__LINE__, |
| 13050 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13051 | AUTH_NONE, |
| 13052 | OK, |
| 13053 | kSecureServer, |
| 13054 | AUTH_SYNC, |
| 13055 | OK, |
| 13056 | 2, |
| 13057 | 0, |
| 13058 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13059 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13060 | {__LINE__, |
| 13061 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13062 | AUTH_NONE, |
| 13063 | OK, |
| 13064 | kSecureServer, |
| 13065 | AUTH_SYNC, |
| 13066 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13067 | 2, |
| 13068 | 0, |
| 13069 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13070 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13071 | {__LINE__, |
| 13072 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13073 | AUTH_NONE, |
| 13074 | OK, |
| 13075 | kSecureServer, |
| 13076 | AUTH_ASYNC, |
| 13077 | OK, |
| 13078 | 2, |
| 13079 | 0, |
| 13080 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13081 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13082 | {__LINE__, |
| 13083 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13084 | AUTH_NONE, |
| 13085 | OK, |
| 13086 | kSecureServer, |
| 13087 | AUTH_ASYNC, |
| 13088 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13089 | 2, |
| 13090 | 0, |
| 13091 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13092 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13093 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13094 | {__LINE__, |
| 13095 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13096 | AUTH_SYNC, |
| 13097 | OK, |
| 13098 | kSecureServer, |
| 13099 | AUTH_NONE, |
| 13100 | OK, |
| 13101 | 2, |
| 13102 | 1, |
| 13103 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13104 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13105 | {__LINE__, |
| 13106 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13107 | AUTH_SYNC, |
| 13108 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13109 | kSecureServer, |
| 13110 | AUTH_NONE, |
| 13111 | OK, |
| 13112 | 2, |
| 13113 | kNoSSL, |
| 13114 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13115 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13116 | {__LINE__, |
| 13117 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13118 | AUTH_SYNC, |
| 13119 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13120 | kSecureServer, |
| 13121 | AUTH_NONE, |
| 13122 | OK, |
| 13123 | 2, |
| 13124 | kNoSSL, |
| 13125 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13126 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13127 | {__LINE__, |
| 13128 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13129 | AUTH_SYNC, |
| 13130 | ERR_UNEXPECTED, |
| 13131 | kSecureServer, |
| 13132 | AUTH_NONE, |
| 13133 | OK, |
| 13134 | 2, |
| 13135 | kNoSSL, |
| 13136 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13137 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13138 | {__LINE__, |
| 13139 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13140 | AUTH_ASYNC, |
| 13141 | OK, |
| 13142 | kSecureServer, |
| 13143 | AUTH_NONE, |
| 13144 | OK, |
| 13145 | 2, |
| 13146 | 1, |
| 13147 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13148 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13149 | {__LINE__, |
| 13150 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13151 | AUTH_ASYNC, |
| 13152 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13153 | kSecureServer, |
| 13154 | AUTH_NONE, |
| 13155 | OK, |
| 13156 | 2, |
| 13157 | kNoSSL, |
| 13158 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13159 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13160 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13161 | {__LINE__, |
| 13162 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13163 | AUTH_SYNC, |
| 13164 | OK, |
| 13165 | kSecureServer, |
| 13166 | AUTH_SYNC, |
| 13167 | OK, |
| 13168 | 3, |
| 13169 | 1, |
| 13170 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13171 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13172 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13173 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13174 | {__LINE__, |
| 13175 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13176 | AUTH_SYNC, |
| 13177 | OK, |
| 13178 | kSecureServer, |
| 13179 | AUTH_SYNC, |
| 13180 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13181 | 3, |
| 13182 | 1, |
| 13183 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13184 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13185 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13186 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13187 | {__LINE__, |
| 13188 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13189 | AUTH_ASYNC, |
| 13190 | OK, |
| 13191 | kSecureServer, |
| 13192 | AUTH_SYNC, |
| 13193 | OK, |
| 13194 | 3, |
| 13195 | 1, |
| 13196 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13197 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13198 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13199 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13200 | {__LINE__, |
| 13201 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13202 | AUTH_ASYNC, |
| 13203 | OK, |
| 13204 | kSecureServer, |
| 13205 | AUTH_SYNC, |
| 13206 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13207 | 3, |
| 13208 | 1, |
| 13209 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13210 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13211 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13212 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13213 | {__LINE__, |
| 13214 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13215 | AUTH_SYNC, |
| 13216 | OK, |
| 13217 | kSecureServer, |
| 13218 | AUTH_ASYNC, |
| 13219 | OK, |
| 13220 | 3, |
| 13221 | 1, |
| 13222 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13223 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13224 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13225 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13226 | {__LINE__, |
| 13227 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13228 | AUTH_SYNC, |
| 13229 | OK, |
| 13230 | kSecureServer, |
| 13231 | AUTH_ASYNC, |
| 13232 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13233 | 3, |
| 13234 | 1, |
| 13235 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13236 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13237 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13238 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13239 | {__LINE__, |
| 13240 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13241 | AUTH_ASYNC, |
| 13242 | OK, |
| 13243 | kSecureServer, |
| 13244 | AUTH_ASYNC, |
| 13245 | OK, |
| 13246 | 3, |
| 13247 | 1, |
| 13248 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13249 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13250 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13251 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13252 | {__LINE__, |
| 13253 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13254 | AUTH_ASYNC, |
| 13255 | OK, |
| 13256 | kSecureServer, |
| 13257 | AUTH_ASYNC, |
| 13258 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13259 | 3, |
| 13260 | 1, |
| 13261 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13262 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13263 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13264 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13265 | {__LINE__, |
| 13266 | kProxy, |
| 13267 | AUTH_ASYNC, |
| 13268 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13269 | kSecureServer, |
| 13270 | AUTH_ASYNC, |
| 13271 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13272 | 4, |
| 13273 | 2, |
| 13274 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13275 | TestRound(kConnect, kProxyChallenge, OK), |
| 13276 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13277 | &kServerChallenge), |
| 13278 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13279 | }; |
| 13280 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13281 | for (const auto& test_config : test_configs) { |
| 13282 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 13283 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13284 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13285 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13286 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13287 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13288 | |
| 13289 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13290 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13291 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13292 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13293 | std::string auth_challenge = "Mock realm=proxy"; |
| 13294 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13295 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13296 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13297 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13298 | empty_ssl_info, origin, |
| 13299 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13300 | auth_handler->SetGenerateExpectation( |
| 13301 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13302 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13303 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 13304 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13305 | } |
| 13306 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 13307 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13308 | std::string auth_challenge = "Mock realm=server"; |
| 13309 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13310 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13311 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13312 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13313 | empty_ssl_info, origin, |
| 13314 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13315 | auth_handler->SetGenerateExpectation( |
| 13316 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13317 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13318 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13319 | |
| 13320 | // The second handler always succeeds. It should only be used where there |
| 13321 | // are multiple auth sessions for server auth in the same network |
| 13322 | // transaction using the same auth scheme. |
| 13323 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13324 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13325 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 13326 | empty_ssl_info, origin, |
| 13327 | NetLogWithSource()); |
| 13328 | second_handler->SetGenerateExpectation(true, OK); |
| 13329 | auth_factory->AddMockHandler(second_handler.release(), |
| 13330 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13331 | } |
| 13332 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13333 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13334 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 13335 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13336 | } else { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13337 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13338 | } |
| 13339 | |
| 13340 | HttpRequestInfo request; |
| 13341 | request.method = "GET"; |
| 13342 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13343 | request.traffic_annotation = |
| 13344 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13345 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13346 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13347 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13348 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 13349 | |
| 13350 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 13351 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13352 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13353 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13354 | const TestRound& read_write_round = test_config.rounds[round]; |
| 13355 | |
| 13356 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13357 | mock_reads.back().push_back(read_write_round.read); |
| 13358 | mock_writes.back().push_back(read_write_round.write); |
| 13359 | |
| 13360 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 13361 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 13362 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13363 | mock_reads.push_back(std::vector<MockRead>()); |
| 13364 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13365 | } |
| 13366 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13367 | if (read_write_round.extra_read) { |
| 13368 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13369 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13370 | if (read_write_round.extra_write) { |
| 13371 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 13372 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13373 | |
| 13374 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13375 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13376 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13377 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13378 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13379 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13380 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13381 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13382 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13383 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13384 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13385 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 13386 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13387 | } |
| 13388 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13389 | // Transaction must be created after DataProviders, so it's destroyed before |
| 13390 | // they are as well. |
| 13391 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13392 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13393 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13394 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13395 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13396 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13397 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13398 | int rv; |
| 13399 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13400 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13401 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13402 | rv = trans.RestartWithAuth( |
| 13403 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13404 | } |
| 13405 | if (rv == ERR_IO_PENDING) |
| 13406 | rv = callback.WaitForResult(); |
| 13407 | |
| 13408 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13409 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13410 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 13411 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13412 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 13413 | continue; |
| 13414 | } |
| 13415 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13416 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13417 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13418 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13419 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13420 | } |
| 13421 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 13422 | } |
| 13423 | } |
| 13424 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13425 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13426 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13427 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13428 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13429 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13430 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13431 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 13432 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13433 | |
| 13434 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13435 | auth_handler->set_connection_based(true); |
| 13436 | std::string auth_challenge = "Mock realm=server"; |
| 13437 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13438 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13439 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13440 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13441 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13442 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13443 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13444 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13445 | int rv = OK; |
| 13446 | const HttpResponseInfo* response = NULL; |
| 13447 | HttpRequestInfo request; |
| 13448 | request.method = "GET"; |
| 13449 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13450 | request.traffic_annotation = |
| 13451 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13452 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13453 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13454 | |
| 13455 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 13456 | // to validate that the TCP socket is not released to the pool between |
| 13457 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13458 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13459 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13460 | 50, // Max sockets for pool |
| 13461 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 13462 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 13463 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13464 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 13465 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 13466 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13468 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13469 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13470 | |
| 13471 | const MockWrite kGet( |
| 13472 | "GET / HTTP/1.1\r\n" |
| 13473 | "Host: www.example.com\r\n" |
| 13474 | "Connection: keep-alive\r\n\r\n"); |
| 13475 | const MockWrite kGetAuth( |
| 13476 | "GET / HTTP/1.1\r\n" |
| 13477 | "Host: www.example.com\r\n" |
| 13478 | "Connection: keep-alive\r\n" |
| 13479 | "Authorization: auth_token\r\n\r\n"); |
| 13480 | |
| 13481 | const MockRead kServerChallenge( |
| 13482 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13483 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13484 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13485 | "Content-Length: 14\r\n\r\n" |
| 13486 | "Unauthorized\r\n"); |
| 13487 | const MockRead kSuccess( |
| 13488 | "HTTP/1.1 200 OK\r\n" |
| 13489 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13490 | "Content-Length: 3\r\n\r\n" |
| 13491 | "Yes"); |
| 13492 | |
| 13493 | MockWrite writes[] = { |
| 13494 | // First round |
| 13495 | kGet, |
| 13496 | // Second round |
| 13497 | kGetAuth, |
| 13498 | // Third round |
| 13499 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13500 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13501 | kGetAuth, |
| 13502 | // Competing request |
| 13503 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13504 | }; |
| 13505 | MockRead reads[] = { |
| 13506 | // First round |
| 13507 | kServerChallenge, |
| 13508 | // Second round |
| 13509 | kServerChallenge, |
| 13510 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13511 | kServerChallenge, |
| 13512 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13513 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13514 | // Competing response |
| 13515 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13516 | }; |
| 13517 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 13518 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13519 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13520 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13521 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13522 | |
| 13523 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13524 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13525 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13526 | if (rv == ERR_IO_PENDING) |
| 13527 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13528 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13529 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13530 | ASSERT_TRUE(response); |
| 13531 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13532 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13533 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13534 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13535 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13536 | // In between rounds, another request comes in for the same domain. |
| 13537 | // It should not be able to grab the TCP socket that trans has already |
| 13538 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13539 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13540 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13541 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 13542 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13544 | // callback_compete.WaitForResult at this point would stall forever, |
| 13545 | // since the HttpNetworkTransaction does not release the request back to |
| 13546 | // the pool until after authentication completes. |
| 13547 | |
| 13548 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13549 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13550 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13551 | if (rv == ERR_IO_PENDING) |
| 13552 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13553 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13554 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13555 | ASSERT_TRUE(response); |
| 13556 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13557 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13558 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13559 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13560 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13561 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13562 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13563 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13564 | if (rv == ERR_IO_PENDING) |
| 13565 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13566 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13567 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13568 | ASSERT_TRUE(response); |
| 13569 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13570 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13571 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13572 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13573 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13574 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13575 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13576 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13577 | if (rv == ERR_IO_PENDING) |
| 13578 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13579 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13580 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13581 | ASSERT_TRUE(response); |
| 13582 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13583 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13584 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13585 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 13586 | // auth handler should transition to a DONE state in concert with the remote |
| 13587 | // server. But that's not something we can test here with a mock handler. |
| 13588 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 13589 | auth_handler->state()); |
| 13590 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13591 | // Read the body since the fourth round was successful. This will also |
| 13592 | // release the socket back to the pool. |
| 13593 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13594 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13595 | if (rv == ERR_IO_PENDING) |
| 13596 | rv = callback.WaitForResult(); |
| 13597 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13598 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13599 | EXPECT_EQ(0, rv); |
| 13600 | // There are still 0 idle sockets, since the trans_compete transaction |
| 13601 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13602 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13603 | |
| 13604 | // The competing request can now finish. Wait for the headers and then |
| 13605 | // read the body. |
| 13606 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13607 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13608 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13609 | if (rv == ERR_IO_PENDING) |
| 13610 | rv = callback.WaitForResult(); |
| 13611 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13612 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13613 | EXPECT_EQ(0, rv); |
| 13614 | |
| 13615 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13616 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13617 | } |
| 13618 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13619 | // This tests the case that a request is issued via http instead of spdy after |
| 13620 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13621 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13622 | HttpRequestInfo request; |
| 13623 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13624 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13625 | request.traffic_annotation = |
| 13626 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13627 | |
| 13628 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13629 | MockWrite( |
| 13630 | "GET / HTTP/1.1\r\n" |
| 13631 | "Host: www.example.org\r\n" |
| 13632 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13633 | }; |
| 13634 | |
| 13635 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13636 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13637 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13638 | MockRead("\r\n"), |
| 13639 | MockRead("hello world"), |
| 13640 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13641 | }; |
| 13642 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13643 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13644 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13645 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13646 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13647 | |
| 13648 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13649 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13650 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13651 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13652 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13653 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13654 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13656 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13657 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13658 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13659 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13660 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13661 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13662 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13663 | ASSERT_TRUE(response); |
| 13664 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13665 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13666 | |
| 13667 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13668 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13669 | EXPECT_EQ("hello world", response_data); |
| 13670 | |
| 13671 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13672 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13673 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13674 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13675 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 13676 | // immediate server closing of the socket. |
| 13677 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13678 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13679 | HttpRequestInfo request; |
| 13680 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13681 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13682 | request.traffic_annotation = |
| 13683 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13684 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13685 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13686 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13687 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13688 | |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 13689 | SpdySerializedFrame req(spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13690 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13691 | |
| 13692 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13693 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13694 | }; |
| 13695 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13696 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13697 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13698 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13699 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13700 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13701 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13702 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13703 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13704 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13705 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13706 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13707 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13708 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13709 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13710 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 13711 | // it gets it. This is needed since the auth handler may get destroyed |
| 13712 | // before we get a chance to query it. |
| 13713 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 13714 | public: |
| 13715 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 13716 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 13717 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13718 | |
| 13719 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13720 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 13721 | const HttpRequestInfo* request, |
| 13722 | const CompletionCallback& callback, |
| 13723 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13724 | *url_ = request->url; |
| 13725 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 13726 | credentials, request, callback, auth_token); |
| 13727 | } |
| 13728 | |
| 13729 | private: |
| 13730 | GURL* url_; |
| 13731 | }; |
| 13732 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13733 | // Test that if we cancel the transaction as the connection is completing, that |
| 13734 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13735 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13736 | // Setup everything about the connection to complete synchronously, so that |
| 13737 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13738 | // for is the callback from the HttpStreamRequest. |
| 13739 | // Then cancel the transaction. |
| 13740 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13741 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13742 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13743 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13744 | MockRead(SYNCHRONOUS, "hello world"), |
| 13745 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13746 | }; |
| 13747 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13748 | HttpRequestInfo request; |
| 13749 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13750 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13751 | request.traffic_annotation = |
| 13752 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13753 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13754 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13756 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13757 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13758 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13759 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13760 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13761 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13762 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13763 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13764 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13765 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13766 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13767 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13768 | trans.reset(); // Cancel the transaction here. |
| 13769 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13770 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13771 | } |
| 13772 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13773 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13774 | // stream is drained properly and added back to the socket pool. The main |
| 13775 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13776 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13777 | // deleted. |
| 13778 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13779 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13780 | MockRead data_reads[] = { |
| 13781 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13782 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13783 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13784 | MockRead(ASYNC, "1"), |
| 13785 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13786 | // HttpNetworkTransaction has been deleted. |
| 13787 | MockRead(ASYNC, "2"), |
| 13788 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13789 | }; |
| 13790 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13791 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13792 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13793 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13794 | |
| 13795 | { |
| 13796 | HttpRequestInfo request; |
| 13797 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13798 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13799 | request.traffic_annotation = |
| 13800 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13801 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13802 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13803 | TestCompletionCallback callback; |
| 13804 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13805 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13806 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13807 | callback.WaitForResult(); |
| 13808 | |
| 13809 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13810 | ASSERT_TRUE(response); |
| 13811 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13812 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13813 | |
| 13814 | // The transaction and HttpRequestInfo are deleted. |
| 13815 | } |
| 13816 | |
| 13817 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13818 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13819 | |
| 13820 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13821 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13822 | } |
| 13823 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13824 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13825 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13826 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13827 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13828 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13829 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13830 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13832 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13833 | HttpRequestInfo request; |
| 13834 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13835 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13836 | request.traffic_annotation = |
| 13837 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13838 | |
| 13839 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13840 | MockWrite( |
| 13841 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13842 | "Host: www.example.org\r\n" |
| 13843 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13844 | }; |
| 13845 | |
| 13846 | MockRead data_reads1[] = { |
| 13847 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13848 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13849 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13850 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13851 | }; |
| 13852 | |
| 13853 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13854 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13855 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13856 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13857 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13858 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13859 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13860 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13861 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13862 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13863 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13864 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13865 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13866 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13867 | |
| 13868 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13869 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13870 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13871 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13872 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13873 | |
| 13874 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13875 | EXPECT_EQ(200, response->headers->response_code()); |
| 13876 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13877 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13878 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13879 | HostPortPair::FromString("myproxy:70")), |
| 13880 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13881 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13882 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13883 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13884 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13885 | |
| 13886 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13887 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13888 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13889 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13890 | } |
| 13891 | |
| 13892 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13893 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13894 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13895 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13896 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13897 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13898 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13899 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13900 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13901 | HttpRequestInfo request; |
| 13902 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13903 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13904 | request.traffic_annotation = |
| 13905 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13906 | |
| 13907 | // Since we have proxy, should try to establish tunnel. |
| 13908 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13909 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13910 | "Host: www.example.org:443\r\n" |
| 13911 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13912 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13913 | MockWrite("GET / HTTP/1.1\r\n" |
| 13914 | "Host: www.example.org\r\n" |
| 13915 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13916 | }; |
| 13917 | |
| 13918 | MockRead data_reads1[] = { |
| 13919 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13920 | |
| 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] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13930 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13931 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13932 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13933 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13934 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13935 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13936 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13937 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13938 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13939 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13940 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13941 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13942 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13943 | |
| 13944 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13945 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13946 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13947 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13948 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13949 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13950 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13951 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13952 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13953 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13954 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13955 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13956 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13957 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13958 | |
| 13959 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13960 | EXPECT_EQ(200, response->headers->response_code()); |
| 13961 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13962 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13963 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13964 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13965 | HostPortPair::FromString("myproxy:70")), |
| 13966 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13967 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13968 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13969 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13970 | |
| 13971 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13972 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13973 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13974 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13975 | } |
| 13976 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13977 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13978 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13979 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13980 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13981 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13982 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13983 | BoundTestNetLog log; |
| 13984 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13985 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13986 | |
| 13987 | HttpRequestInfo request; |
| 13988 | request.method = "GET"; |
| 13989 | request.url = GURL("https://[::1]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13990 | request.traffic_annotation = |
| 13991 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13992 | |
| 13993 | // Since we have proxy, should try to establish tunnel. |
| 13994 | MockWrite data_writes1[] = { |
| 13995 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13996 | "Host: [::1]:443\r\n" |
| 13997 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13998 | |
| 13999 | MockWrite("GET / HTTP/1.1\r\n" |
| 14000 | "Host: [::1]\r\n" |
| 14001 | "Connection: keep-alive\r\n\r\n"), |
| 14002 | }; |
| 14003 | |
| 14004 | MockRead data_reads1[] = { |
| 14005 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14006 | |
| 14007 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14008 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14009 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14010 | MockRead(SYNCHRONOUS, OK), |
| 14011 | }; |
| 14012 | |
| 14013 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 14014 | data_writes1, arraysize(data_writes1)); |
| 14015 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14016 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14017 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14018 | |
| 14019 | TestCompletionCallback callback1; |
| 14020 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14021 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14022 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14023 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14024 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14025 | |
| 14026 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14027 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14028 | TestNetLogEntry::List entries; |
| 14029 | log.GetEntries(&entries); |
| 14030 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14031 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14032 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14033 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14034 | entries, pos, |
| 14035 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14036 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14037 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14038 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14039 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14040 | |
| 14041 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14042 | EXPECT_EQ(200, response->headers->response_code()); |
| 14043 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14044 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14045 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14046 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14047 | HostPortPair::FromString("myproxy:70")), |
| 14048 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14049 | |
| 14050 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14051 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14052 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14053 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14054 | } |
| 14055 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14056 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14057 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14058 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14059 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14060 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14061 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14062 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14063 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14064 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14065 | HttpRequestInfo request; |
| 14066 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14067 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14068 | request.traffic_annotation = |
| 14069 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14070 | |
| 14071 | // Since we have proxy, should try to establish tunnel. |
| 14072 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14073 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14074 | "Host: www.example.org:443\r\n" |
| 14075 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14076 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14077 | MockWrite("GET / HTTP/1.1\r\n" |
| 14078 | "Host: www.example.org\r\n" |
| 14079 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14080 | }; |
| 14081 | |
| 14082 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14083 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14084 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14085 | }; |
| 14086 | |
| 14087 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 14088 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14089 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14090 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14091 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14092 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14093 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14095 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [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)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14099 | |
| 14100 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14101 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14102 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14103 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 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); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14107 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14108 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14109 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14110 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14111 | } |
| 14112 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14113 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14114 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14115 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14116 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14117 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14118 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14119 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14120 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14121 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14122 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14123 | }; |
| 14124 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14125 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 14126 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14127 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14128 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14129 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14130 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14131 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14132 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14133 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14134 | |
| 14135 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14136 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14137 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 14138 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14139 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14140 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14141 | |
| 14142 | HttpRequestInfo request; |
| 14143 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14144 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14145 | request.traffic_annotation = |
| 14146 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14147 | |
| 14148 | // This is the important line that marks this as a preconnect. |
| 14149 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 14150 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14151 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14152 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14153 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14154 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14155 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14156 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14157 | } |
| 14158 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14159 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14160 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14161 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14162 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14163 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14164 | request_info.url = GURL("https://www.example.com/"); |
| 14165 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14166 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14167 | request_info.traffic_annotation = |
| 14168 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14169 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14170 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14171 | MockWrite data_writes[] = { |
| 14172 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14173 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14174 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14175 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14176 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14177 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14179 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14181 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14182 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14183 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14184 | rv = callback.WaitForResult(); |
| 14185 | ASSERT_EQ(error, rv); |
| 14186 | } |
| 14187 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14188 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14189 | // Just check a grab bag of cert errors. |
| 14190 | static const int kErrors[] = { |
| 14191 | ERR_CERT_COMMON_NAME_INVALID, |
| 14192 | ERR_CERT_AUTHORITY_INVALID, |
| 14193 | ERR_CERT_DATE_INVALID, |
| 14194 | }; |
| 14195 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14196 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 14197 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14198 | } |
| 14199 | } |
| 14200 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14201 | // Ensure that a client certificate is removed from the SSL client auth |
| 14202 | // cache when: |
| 14203 | // 1) No proxy is involved. |
| 14204 | // 2) TLS False Start is disabled. |
| 14205 | // 3) The initial TLS handshake requests a client certificate. |
| 14206 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14207 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14208 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14209 | request_info.url = GURL("https://www.example.com/"); |
| 14210 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14211 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14212 | request_info.traffic_annotation = |
| 14213 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14214 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14215 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14216 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14217 | |
| 14218 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 14219 | // CertificateRequest is received for the first time, the handshake will |
| 14220 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14221 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14222 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14224 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14225 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14226 | |
| 14227 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 14228 | // False Start is not being used, the result of the SSL handshake will be |
| 14229 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 14230 | // matches the result of a server sending a handshake_failure alert, |
| 14231 | // rather than a Finished message, because it requires a client |
| 14232 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14233 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14234 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14235 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14236 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14237 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14238 | |
| 14239 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 14240 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14241 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 14242 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14243 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14244 | // requiring a client certificate, this fallback handshake should also |
| 14245 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14246 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14247 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14248 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14249 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14250 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14251 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14252 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 14253 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14254 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 14255 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14256 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14257 | // requiring a client certificate, this fallback handshake should also |
| 14258 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14259 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14260 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14261 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14262 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14263 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14264 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14265 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14266 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14267 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14268 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14269 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14270 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14271 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14272 | |
| 14273 | // Complete the SSL handshake, which should abort due to requiring a |
| 14274 | // client certificate. |
| 14275 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14276 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14277 | |
| 14278 | // Indicate that no certificate should be supplied. From the perspective |
| 14279 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14280 | // certificate, so this is the same as supply a |
| 14281 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14282 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14283 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14284 | |
| 14285 | // Ensure the certificate was added to the client auth cache before |
| 14286 | // allowing the connection to continue restarting. |
| 14287 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14288 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14289 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14290 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14291 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14292 | |
| 14293 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14294 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14295 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14296 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14297 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14298 | |
| 14299 | // Ensure that the client certificate is removed from the cache on a |
| 14300 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14301 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14302 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14303 | } |
| 14304 | |
| 14305 | // Ensure that a client certificate is removed from the SSL client auth |
| 14306 | // cache when: |
| 14307 | // 1) No proxy is involved. |
| 14308 | // 2) TLS False Start is enabled. |
| 14309 | // 3) The initial TLS handshake requests a client certificate. |
| 14310 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14311 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14312 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14313 | request_info.url = GURL("https://www.example.com/"); |
| 14314 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14315 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14316 | request_info.traffic_annotation = |
| 14317 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14318 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14319 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14320 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14321 | |
| 14322 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 14323 | // return successfully after reading up to the peer's Certificate message. |
| 14324 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 14325 | // enqueue application data to be sent in the same packet as the |
| 14326 | // ChangeCipherSpec and Finished messages. |
| 14327 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 14328 | // called, which expects to process the peer's ChangeCipherSpec and |
| 14329 | // Finished messages. If there was an error negotiating with the peer, |
| 14330 | // such as due to the peer requiring a client certificate when none was |
| 14331 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 14332 | // called. |
| 14333 | |
| 14334 | // Like the non-False Start case, when a client certificate is requested by |
| 14335 | // the peer, the handshake is aborted during the Connect() call. |
| 14336 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14337 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14338 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14339 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14340 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14341 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14342 | |
| 14343 | // When a client certificate is supplied, Connect() will not be aborted |
| 14344 | // when the peer requests the certificate. Instead, the handshake will |
| 14345 | // artificially succeed, allowing the caller to write the HTTP request to |
| 14346 | // the socket. The handshake messages are not processed until Read() is |
| 14347 | // called, which then detects that the handshake was aborted, due to the |
| 14348 | // peer sending a handshake_failure because it requires a client |
| 14349 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14350 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14351 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14352 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14353 | MockRead data2_reads[] = { |
| 14354 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14355 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14356 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14357 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14358 | |
| 14359 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14360 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 14361 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14362 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14363 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14365 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14366 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14367 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14368 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 14369 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14370 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14371 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14372 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14373 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14374 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14375 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14376 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14377 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14378 | ssl_data5.cert_request_info = cert_request.get(); |
| 14379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14380 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14381 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 14382 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14383 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14384 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14385 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14386 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14387 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14388 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14389 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14390 | |
| 14391 | // Complete the SSL handshake, which should abort due to requiring a |
| 14392 | // client certificate. |
| 14393 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14394 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14395 | |
| 14396 | // Indicate that no certificate should be supplied. From the perspective |
| 14397 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14398 | // certificate, so this is the same as supply a |
| 14399 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14400 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14401 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14402 | |
| 14403 | // Ensure the certificate was added to the client auth cache before |
| 14404 | // allowing the connection to continue restarting. |
| 14405 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14406 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14407 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14408 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14409 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14410 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14411 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14412 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14413 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14414 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14415 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14416 | |
| 14417 | // Ensure that the client certificate is removed from the cache on a |
| 14418 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14419 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14420 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14421 | } |
| 14422 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14423 | // Ensure that a client certificate is removed from the SSL client auth |
| 14424 | // cache when: |
| 14425 | // 1) An HTTPS proxy is involved. |
| 14426 | // 3) The HTTPS proxy requests a client certificate. |
| 14427 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 14428 | // proxy. |
| 14429 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 14430 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14431 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14432 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14433 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14434 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14435 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14436 | |
| 14437 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14438 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14439 | |
| 14440 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 14441 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 14442 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 14443 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14444 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14445 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14446 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14447 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14448 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14449 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14450 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14451 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14452 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14453 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14454 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14455 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14456 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 14457 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14458 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14459 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14460 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14461 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14462 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14463 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14464 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14465 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14466 | requests[0].url = GURL("https://www.example.com/"); |
| 14467 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14468 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14469 | requests[0].traffic_annotation = |
| 14470 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14471 | |
| 14472 | requests[1].url = GURL("http://www.example.com/"); |
| 14473 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14474 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14475 | requests[1].traffic_annotation = |
| 14476 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14477 | |
| 14478 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14479 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14480 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14481 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14482 | |
| 14483 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14484 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14485 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14486 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14487 | |
| 14488 | // Complete the SSL handshake, which should abort due to requiring a |
| 14489 | // client certificate. |
| 14490 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14491 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14492 | |
| 14493 | // Indicate that no certificate should be supplied. From the perspective |
| 14494 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14495 | // certificate, so this is the same as supply a |
| 14496 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14497 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14498 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14499 | |
| 14500 | // Ensure the certificate was added to the client auth cache before |
| 14501 | // allowing the connection to continue restarting. |
| 14502 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14503 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14504 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14505 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14506 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14507 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 14508 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14509 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14510 | HostPortPair("www.example.com", 443), &client_cert, |
| 14511 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14512 | |
| 14513 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 14514 | // then consume ssl_data3, which should also fail. The result code is |
| 14515 | // checked against what ssl_data3 should return. |
| 14516 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14517 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14518 | |
| 14519 | // Now that the new handshake has failed, ensure that the client |
| 14520 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14521 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14522 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14523 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14524 | HostPortPair("www.example.com", 443), &client_cert, |
| 14525 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14526 | } |
| 14527 | } |
| 14528 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14529 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14530 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14531 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14532 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14533 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14534 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14535 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14536 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14537 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14538 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14539 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14540 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14541 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14542 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14543 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14544 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14545 | SpdySerializedFrame host1_resp_body( |
| 14546 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14547 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14548 | SpdySerializedFrame host2_resp_body( |
| 14549 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14550 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14551 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14552 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14553 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14554 | }; |
| 14555 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14556 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14557 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14558 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14559 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14560 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14561 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14562 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14563 | HttpRequestInfo request1; |
| 14564 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14565 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14566 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14567 | request1.traffic_annotation = |
| 14568 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14569 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14570 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14571 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14572 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14573 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14574 | |
| 14575 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14576 | ASSERT_TRUE(response); |
| 14577 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14578 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14579 | |
| 14580 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14581 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14582 | EXPECT_EQ("hello!", response_data); |
| 14583 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14584 | // Preload mail.example.com into HostCache. |
| 14585 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 14586 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14587 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14588 | std::unique_ptr<HostResolver::Request> request; |
| 14589 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14590 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14591 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14592 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14593 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14594 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14595 | |
| 14596 | HttpRequestInfo request2; |
| 14597 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14598 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14599 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14600 | request2.traffic_annotation = |
| 14601 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14602 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14603 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14604 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14606 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14607 | |
| 14608 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14609 | ASSERT_TRUE(response); |
| 14610 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14611 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14612 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14613 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14614 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14615 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14616 | } |
| 14617 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14618 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14619 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14620 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14621 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14622 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14623 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14624 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14625 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14626 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14627 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14628 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14629 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14630 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14631 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14632 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14633 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14634 | SpdySerializedFrame host1_resp_body( |
| 14635 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14636 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14637 | SpdySerializedFrame host2_resp_body( |
| 14638 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14639 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14640 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14641 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14642 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14643 | }; |
| 14644 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14645 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14646 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14647 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14648 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14649 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14650 | |
| 14651 | TestCompletionCallback callback; |
| 14652 | HttpRequestInfo request1; |
| 14653 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14654 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14655 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14656 | request1.traffic_annotation = |
| 14657 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14658 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14659 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14660 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14661 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14662 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14663 | |
| 14664 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14665 | ASSERT_TRUE(response); |
| 14666 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14667 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14668 | |
| 14669 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14670 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14671 | EXPECT_EQ("hello!", response_data); |
| 14672 | |
| 14673 | HttpRequestInfo request2; |
| 14674 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14675 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14676 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14677 | request2.traffic_annotation = |
| 14678 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14679 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14680 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14681 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14682 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14683 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14684 | |
| 14685 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14686 | ASSERT_TRUE(response); |
| 14687 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14688 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14689 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14690 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14691 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14692 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14693 | } |
| 14694 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14695 | // Regression test for https://crbug.com/546991. |
| 14696 | // The server might not be able to serve an IP pooled request, and might send a |
| 14697 | // 421 Misdirected Request response status to indicate this. |
| 14698 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 14699 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 14700 | // Two hosts resolve to the same IP address. |
| 14701 | const std::string ip_addr = "1.2.3.4"; |
| 14702 | IPAddress ip; |
| 14703 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14704 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14705 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14706 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14707 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14708 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14709 | |
| 14710 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14711 | |
| 14712 | // Two requests on the first connection. |
| 14713 | SpdySerializedFrame req1( |
| 14714 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14715 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14716 | SpdySerializedFrame req2( |
| 14717 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14718 | SpdySerializedFrame rst( |
| 14719 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14720 | MockWrite writes1[] = { |
| 14721 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14722 | CreateMockWrite(rst, 6), |
| 14723 | }; |
| 14724 | |
| 14725 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14726 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14727 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14728 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14729 | response_headers[kHttp2StatusHeader] = "421"; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14730 | SpdySerializedFrame resp2( |
| 14731 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 14732 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14733 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14734 | |
| 14735 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14736 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14737 | arraysize(writes1)); |
| 14738 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14739 | |
| 14740 | AddSSLSocketData(); |
| 14741 | |
| 14742 | // Retry the second request on a second connection. |
| 14743 | SpdyTestUtil spdy_util2; |
| 14744 | SpdySerializedFrame req3( |
| 14745 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14746 | MockWrite writes2[] = { |
| 14747 | CreateMockWrite(req3, 0), |
| 14748 | }; |
| 14749 | |
| 14750 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14751 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14752 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14753 | MockRead(ASYNC, 0, 3)}; |
| 14754 | |
| 14755 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14756 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14757 | arraysize(writes2)); |
| 14758 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14759 | |
| 14760 | AddSSLSocketData(); |
| 14761 | |
| 14762 | // Preload mail.example.org into HostCache. |
| 14763 | HostPortPair host_port("mail.example.org", 443); |
| 14764 | HostResolver::RequestInfo resolve_info(host_port); |
| 14765 | AddressList ignored; |
| 14766 | std::unique_ptr<HostResolver::Request> request; |
| 14767 | TestCompletionCallback callback; |
| 14768 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14769 | &ignored, callback.callback(), |
| 14770 | &request, NetLogWithSource()); |
| 14771 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14772 | rv = callback.WaitForResult(); |
| 14773 | EXPECT_THAT(rv, IsOk()); |
| 14774 | |
| 14775 | HttpRequestInfo request1; |
| 14776 | request1.method = "GET"; |
| 14777 | request1.url = GURL("https://www.example.org/"); |
| 14778 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14779 | request1.traffic_annotation = |
| 14780 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14781 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14782 | |
| 14783 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14784 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14785 | rv = callback.WaitForResult(); |
| 14786 | EXPECT_THAT(rv, IsOk()); |
| 14787 | |
| 14788 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14789 | ASSERT_TRUE(response); |
| 14790 | ASSERT_TRUE(response->headers); |
| 14791 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14792 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14793 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14794 | std::string response_data; |
| 14795 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14796 | EXPECT_EQ("hello!", response_data); |
| 14797 | |
| 14798 | HttpRequestInfo request2; |
| 14799 | request2.method = "GET"; |
| 14800 | request2.url = GURL("https://mail.example.org/"); |
| 14801 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14802 | request2.traffic_annotation = |
| 14803 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14804 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14805 | |
| 14806 | BoundTestNetLog log; |
| 14807 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14808 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14809 | rv = callback.WaitForResult(); |
| 14810 | EXPECT_THAT(rv, IsOk()); |
| 14811 | |
| 14812 | response = trans2.GetResponseInfo(); |
| 14813 | ASSERT_TRUE(response); |
| 14814 | ASSERT_TRUE(response->headers); |
| 14815 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14816 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14817 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14818 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14819 | EXPECT_EQ("hello!", response_data); |
| 14820 | |
| 14821 | TestNetLogEntry::List entries; |
| 14822 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14823 | ExpectLogContainsSomewhere( |
| 14824 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14825 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14826 | } |
| 14827 | |
| 14828 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14829 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14830 | // portions of the response. |
| 14831 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14832 | // Two hosts resolve to the same IP address. |
| 14833 | const std::string ip_addr = "1.2.3.4"; |
| 14834 | IPAddress ip; |
| 14835 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14836 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14837 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14838 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14839 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14840 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14841 | |
| 14842 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14843 | |
| 14844 | // Two requests on the first connection. |
| 14845 | SpdySerializedFrame req1( |
| 14846 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14847 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14848 | SpdySerializedFrame req2( |
| 14849 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14850 | SpdySerializedFrame rst( |
| 14851 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14852 | MockWrite writes1[] = { |
| 14853 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14854 | CreateMockWrite(rst, 6), |
| 14855 | }; |
| 14856 | |
| 14857 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14858 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14859 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14860 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14861 | response_headers[kHttp2StatusHeader] = "421"; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14862 | SpdySerializedFrame resp2( |
| 14863 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14864 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14865 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14866 | |
| 14867 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14868 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14869 | arraysize(writes1)); |
| 14870 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14871 | |
| 14872 | AddSSLSocketData(); |
| 14873 | |
| 14874 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14875 | // Retry again. |
| 14876 | SpdyTestUtil spdy_util2; |
| 14877 | SpdySerializedFrame req3( |
| 14878 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14879 | MockWrite writes2[] = { |
| 14880 | CreateMockWrite(req3, 0), |
| 14881 | }; |
| 14882 | |
| 14883 | SpdySerializedFrame resp3( |
| 14884 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 14885 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14886 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14887 | MockRead(ASYNC, 0, 3)}; |
| 14888 | |
| 14889 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14890 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14891 | arraysize(writes2)); |
| 14892 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14893 | |
| 14894 | AddSSLSocketData(); |
| 14895 | |
| 14896 | // Preload mail.example.org into HostCache. |
| 14897 | HostPortPair host_port("mail.example.org", 443); |
| 14898 | HostResolver::RequestInfo resolve_info(host_port); |
| 14899 | AddressList ignored; |
| 14900 | std::unique_ptr<HostResolver::Request> request; |
| 14901 | TestCompletionCallback callback; |
| 14902 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14903 | &ignored, callback.callback(), |
| 14904 | &request, NetLogWithSource()); |
| 14905 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14906 | rv = callback.WaitForResult(); |
| 14907 | EXPECT_THAT(rv, IsOk()); |
| 14908 | |
| 14909 | HttpRequestInfo request1; |
| 14910 | request1.method = "GET"; |
| 14911 | request1.url = GURL("https://www.example.org/"); |
| 14912 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14913 | request1.traffic_annotation = |
| 14914 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14915 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14916 | |
| 14917 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14918 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14919 | rv = callback.WaitForResult(); |
| 14920 | EXPECT_THAT(rv, IsOk()); |
| 14921 | |
| 14922 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14923 | ASSERT_TRUE(response); |
| 14924 | ASSERT_TRUE(response->headers); |
| 14925 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14926 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14927 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14928 | std::string response_data; |
| 14929 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14930 | EXPECT_EQ("hello!", response_data); |
| 14931 | |
| 14932 | HttpRequestInfo request2; |
| 14933 | request2.method = "GET"; |
| 14934 | request2.url = GURL("https://mail.example.org/"); |
| 14935 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14936 | request2.traffic_annotation = |
| 14937 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14938 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14939 | |
| 14940 | BoundTestNetLog log; |
| 14941 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14942 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14943 | rv = callback.WaitForResult(); |
| 14944 | EXPECT_THAT(rv, IsOk()); |
| 14945 | |
| 14946 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14947 | // caller. |
| 14948 | response = trans2.GetResponseInfo(); |
| 14949 | ASSERT_TRUE(response); |
| 14950 | ASSERT_TRUE(response->headers); |
| 14951 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14952 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14953 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14954 | EXPECT_TRUE(response->ssl_info.cert); |
| 14955 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14956 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14957 | } |
| 14958 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14959 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14960 | public: |
| 14961 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14962 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14963 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14964 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14965 | int ResolveFromCache(const RequestInfo& info, |
| 14966 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14967 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14968 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14969 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14970 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14971 | return rv; |
| 14972 | } |
| 14973 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14974 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14975 | const HostPortPair host_port_; |
| 14976 | }; |
| 14977 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14978 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14979 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14980 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14981 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14982 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14983 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14984 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14985 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14986 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14987 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14988 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14989 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14990 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14991 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14992 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14993 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14994 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14995 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14996 | SpdySerializedFrame host1_resp_body( |
| 14997 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14998 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14999 | SpdySerializedFrame host2_resp_body( |
| 15000 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15001 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15002 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15003 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15004 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15005 | }; |
| 15006 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15007 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15008 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15009 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 15010 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15011 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15012 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15013 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15014 | HttpRequestInfo request1; |
| 15015 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15016 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15017 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15018 | request1.traffic_annotation = |
| 15019 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15020 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15021 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15022 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15023 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15024 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15025 | |
| 15026 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15027 | ASSERT_TRUE(response); |
| 15028 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15029 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15030 | |
| 15031 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15032 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15033 | EXPECT_EQ("hello!", response_data); |
| 15034 | |
| 15035 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15036 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15037 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15038 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15039 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15040 | &ignored, callback.callback(), |
| 15041 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15042 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15043 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15044 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15045 | |
| 15046 | HttpRequestInfo request2; |
| 15047 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15048 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15049 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15050 | request2.traffic_annotation = |
| 15051 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15052 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15053 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15054 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15056 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15057 | |
| 15058 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15059 | ASSERT_TRUE(response); |
| 15060 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15061 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15062 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15063 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15064 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15065 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15066 | } |
| 15067 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15068 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15069 | const std::string https_url = "https://www.example.org:8080/"; |
| 15070 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15071 | |
| 15072 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15073 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15074 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15075 | |
| 15076 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15077 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15078 | }; |
| 15079 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15080 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15081 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15082 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15083 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15084 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15085 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15086 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15087 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15088 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15089 | |
| 15090 | // HTTP GET for the HTTP URL |
| 15091 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15092 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15093 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15094 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15095 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15096 | }; |
| 15097 | |
| 15098 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15099 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15100 | MockRead(ASYNC, 2, "hello"), |
| 15101 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15102 | }; |
| 15103 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15104 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15105 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15106 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15107 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15108 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15109 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15110 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15111 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15112 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15113 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15114 | |
| 15115 | // Start the first transaction to set up the SpdySession |
| 15116 | HttpRequestInfo request1; |
| 15117 | request1.method = "GET"; |
| 15118 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15119 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15120 | request1.traffic_annotation = |
| 15121 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15122 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15123 | TestCompletionCallback callback1; |
| 15124 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15125 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15126 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15127 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15128 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15129 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15130 | |
| 15131 | // Now, start the HTTP request |
| 15132 | HttpRequestInfo request2; |
| 15133 | request2.method = "GET"; |
| 15134 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15135 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15136 | request2.traffic_annotation = |
| 15137 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15138 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15139 | TestCompletionCallback callback2; |
| 15140 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15141 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15142 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15143 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15144 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15145 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15146 | } |
| 15147 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15148 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15149 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15150 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15151 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15152 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15153 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15154 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15155 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15156 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15157 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15158 | |
| 15159 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15160 | // negotiated. |
| 15161 | StaticSocketDataProvider data; |
| 15162 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15163 | |
| 15164 | // 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] | 15165 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15166 | // mocked. This way the request relies on the alternate Job. |
| 15167 | StaticSocketDataProvider data_refused; |
| 15168 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15169 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15170 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15171 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15173 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15174 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15175 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15176 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15177 | http_server_properties->SetHttp2AlternativeService( |
| 15178 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15179 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15180 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15181 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15182 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15183 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15184 | request.traffic_annotation = |
| 15185 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15186 | TestCompletionCallback callback; |
| 15187 | |
| 15188 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15189 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15190 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15191 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15192 | } |
| 15193 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15194 | // 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] | 15195 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15196 | // succeeds, the request should succeed, even if the latter fails because |
| 15197 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15198 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15199 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15200 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15201 | |
| 15202 | // Negotiate HTTP/1.1 with alternative. |
| 15203 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15204 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15205 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 15206 | |
| 15207 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15208 | // negotiated. |
| 15209 | StaticSocketDataProvider data; |
| 15210 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15211 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15212 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15213 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15214 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15215 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 15216 | |
| 15217 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15218 | MockWrite("GET / HTTP/1.1\r\n" |
| 15219 | "Host: www.example.org\r\n" |
| 15220 | "Connection: keep-alive\r\n\r\n"), |
| 15221 | MockWrite("GET /second HTTP/1.1\r\n" |
| 15222 | "Host: www.example.org\r\n" |
| 15223 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15224 | }; |
| 15225 | |
| 15226 | MockRead http_reads[] = { |
| 15227 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15228 | MockRead("Content-Type: text/html\r\n"), |
| 15229 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15230 | MockRead("foobar"), |
| 15231 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15232 | MockRead("Content-Type: text/html\r\n"), |
| 15233 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15234 | MockRead("another"), |
| 15235 | }; |
| 15236 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15237 | http_writes, arraysize(http_writes)); |
| 15238 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15239 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15240 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15241 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15242 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15243 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15244 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15245 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15246 | http_server_properties->SetHttp2AlternativeService( |
| 15247 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15248 | |
| 15249 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15250 | HttpRequestInfo request1; |
| 15251 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15252 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15253 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15254 | request1.traffic_annotation = |
| 15255 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15256 | TestCompletionCallback callback1; |
| 15257 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15258 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15259 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15260 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15261 | |
| 15262 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15263 | ASSERT_TRUE(response1); |
| 15264 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15265 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 15266 | |
| 15267 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15268 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15269 | EXPECT_EQ("foobar", response_data1); |
| 15270 | |
| 15271 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 15272 | // for alternative service. |
| 15273 | EXPECT_TRUE( |
| 15274 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 15275 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15276 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15277 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15278 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15279 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15280 | HttpRequestInfo request2; |
| 15281 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15282 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15283 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15284 | request2.traffic_annotation = |
| 15285 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15286 | TestCompletionCallback callback2; |
| 15287 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15288 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15289 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15290 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15291 | |
| 15292 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15293 | ASSERT_TRUE(response2); |
| 15294 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15295 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 15296 | |
| 15297 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15298 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15299 | EXPECT_EQ("another", response_data2); |
| 15300 | } |
| 15301 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15302 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 15303 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 15304 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15305 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15306 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15307 | HostPortPair alternative("alternative.example.org", 443); |
| 15308 | std::string origin_url = "https://origin.example.org:443"; |
| 15309 | std::string alternative_url = "https://alternative.example.org:443"; |
| 15310 | |
| 15311 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 15312 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15313 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15314 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15315 | |
| 15316 | // HTTP/1.1 data for |request1| and |request2|. |
| 15317 | MockWrite http_writes[] = { |
| 15318 | MockWrite( |
| 15319 | "GET / HTTP/1.1\r\n" |
| 15320 | "Host: alternative.example.org\r\n" |
| 15321 | "Connection: keep-alive\r\n\r\n"), |
| 15322 | MockWrite( |
| 15323 | "GET / HTTP/1.1\r\n" |
| 15324 | "Host: alternative.example.org\r\n" |
| 15325 | "Connection: keep-alive\r\n\r\n"), |
| 15326 | }; |
| 15327 | |
| 15328 | MockRead http_reads[] = { |
| 15329 | MockRead( |
| 15330 | "HTTP/1.1 200 OK\r\n" |
| 15331 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15332 | "Content-Length: 40\r\n\r\n" |
| 15333 | "first HTTP/1.1 response from alternative"), |
| 15334 | MockRead( |
| 15335 | "HTTP/1.1 200 OK\r\n" |
| 15336 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15337 | "Content-Length: 41\r\n\r\n" |
| 15338 | "second HTTP/1.1 response from alternative"), |
| 15339 | }; |
| 15340 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15341 | http_writes, arraysize(http_writes)); |
| 15342 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15343 | |
| 15344 | // This test documents that an alternate Job should not pool to an already |
| 15345 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15346 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15347 | StaticSocketDataProvider data_refused; |
| 15348 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15349 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15350 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15351 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15353 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15354 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15355 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15356 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15357 | http_server_properties->SetHttp2AlternativeService( |
| 15358 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15359 | |
| 15360 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15361 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15362 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15363 | request1.method = "GET"; |
| 15364 | request1.url = GURL(alternative_url); |
| 15365 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15366 | request1.traffic_annotation = |
| 15367 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15368 | TestCompletionCallback callback1; |
| 15369 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15370 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15371 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15372 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15373 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15374 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15375 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15376 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15377 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 15378 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15379 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15380 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 15381 | |
| 15382 | // Request for origin.example.org, which has an alternative service. This |
| 15383 | // will start two Jobs: the alternative looks for connections to pool to, |
| 15384 | // 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] | 15385 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15386 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15387 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15388 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15389 | request2.method = "GET"; |
| 15390 | request2.url = GURL(origin_url); |
| 15391 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15392 | request2.traffic_annotation = |
| 15393 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15394 | TestCompletionCallback callback2; |
| 15395 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15396 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15397 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15398 | |
| 15399 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 15400 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15401 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15402 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15403 | request3.method = "GET"; |
| 15404 | request3.url = GURL(alternative_url); |
| 15405 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15406 | request3.traffic_annotation = |
| 15407 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15408 | TestCompletionCallback callback3; |
| 15409 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15410 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15411 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15412 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15413 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15414 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15415 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15416 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15417 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 15418 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15419 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15420 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 15421 | } |
| 15422 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15423 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15424 | const std::string https_url = "https://www.example.org:8080/"; |
| 15425 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15426 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15427 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15428 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15429 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15430 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15431 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15432 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15433 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15434 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15435 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15436 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15437 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 15438 | |
| 15439 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 15440 | SpdyHeaderBlock req2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 15441 | req2_block[kHttp2MethodHeader] = "GET"; |
| 15442 | req2_block[kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 15443 | req2_block[kHttp2SchemeHeader] = "http"; |
| 15444 | req2_block[kHttp2PathHeader] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15445 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15446 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15447 | |
| 15448 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15449 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 15450 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15451 | }; |
| 15452 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15453 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15454 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15455 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15456 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15457 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 15458 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15459 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15460 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15461 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15462 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15463 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15464 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15465 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15466 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15467 | CreateMockRead(wrapped_resp1, 4), |
| 15468 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15469 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15470 | CreateMockRead(resp2, 8), |
| 15471 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15472 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 15473 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15474 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15475 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15476 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15477 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15478 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15479 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15480 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15481 | ProxyResolutionService::CreateFixedFromPacResult( |
| 15482 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15483 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15484 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15485 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15486 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15487 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15488 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15489 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15490 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15491 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15492 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15493 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15494 | |
| 15495 | // Start the first transaction to set up the SpdySession |
| 15496 | HttpRequestInfo request1; |
| 15497 | request1.method = "GET"; |
| 15498 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15499 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15500 | request1.traffic_annotation = |
| 15501 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15502 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15503 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15504 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15505 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15506 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15507 | data1.RunUntilPaused(); |
| 15508 | base::RunLoop().RunUntilIdle(); |
| 15509 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15510 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15511 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15512 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15513 | LoadTimingInfo load_timing_info1; |
| 15514 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 15515 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 15516 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15517 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15518 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15519 | HttpRequestInfo request2; |
| 15520 | request2.method = "GET"; |
| 15521 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15522 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15523 | request2.traffic_annotation = |
| 15524 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15525 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15526 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15527 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15528 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15529 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15530 | data1.RunUntilPaused(); |
| 15531 | base::RunLoop().RunUntilIdle(); |
| 15532 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15533 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15534 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15535 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15536 | |
| 15537 | LoadTimingInfo load_timing_info2; |
| 15538 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 15539 | // The established SPDY sessions is considered reused by the HTTP request. |
| 15540 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 15541 | // HTTP requests over a SPDY session should have a different connection |
| 15542 | // socket_log_id than requests over a tunnel. |
| 15543 | 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] | 15544 | } |
| 15545 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15546 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 15547 | // that we do not pool other origins that resolve to the same IP when |
| 15548 | // the certificate does not match the new origin. |
| 15549 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15550 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15551 | const std::string url1 = "http://www.example.org/"; |
| 15552 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15553 | const std::string ip_addr = "1.2.3.4"; |
| 15554 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15555 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15556 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15557 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15558 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 15559 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15560 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15561 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15562 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15563 | |
| 15564 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15565 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15566 | }; |
| 15567 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15568 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15569 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15570 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15571 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 15572 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15573 | }; |
| 15574 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15575 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15576 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 15577 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 15578 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15579 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15580 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15581 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15582 | |
| 15583 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15584 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15585 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15586 | |
| 15587 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15588 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15589 | }; |
| 15590 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15591 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15592 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 15593 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15594 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15595 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15596 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15597 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15598 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15599 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15600 | |
| 15601 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 15602 | // all others direct. |
| 15603 | ProxyConfig proxy_config; |
| 15604 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15605 | session_deps_.proxy_resolution_service = |
| 15606 | std::make_unique<ProxyResolutionService>( |
| 15607 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 15608 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 15609 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15610 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15611 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15612 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15613 | // Load a valid cert. Note, that this does not need to |
| 15614 | // be valid for proxy because the MockSSLClientSocket does |
| 15615 | // not actually verify it. But SpdySession will use this |
| 15616 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 15617 | ssl1.ssl_info.cert = |
| 15618 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 15619 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15621 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15622 | |
| 15623 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15624 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15625 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15626 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15627 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15628 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15629 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15630 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15631 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15632 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15633 | |
| 15634 | // Start the first transaction to set up the SpdySession |
| 15635 | HttpRequestInfo request1; |
| 15636 | request1.method = "GET"; |
| 15637 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15638 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15639 | request1.traffic_annotation = |
| 15640 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15641 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15642 | TestCompletionCallback callback1; |
| 15643 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15644 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15645 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15646 | data1.RunUntilPaused(); |
| 15647 | base::RunLoop().RunUntilIdle(); |
| 15648 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15649 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15650 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15651 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15652 | |
| 15653 | // Now, start the HTTP request |
| 15654 | HttpRequestInfo request2; |
| 15655 | request2.method = "GET"; |
| 15656 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15657 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15658 | request2.traffic_annotation = |
| 15659 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15660 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15661 | TestCompletionCallback callback2; |
| 15662 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15663 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15664 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15665 | |
| 15666 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15667 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15668 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15669 | } |
| 15670 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15671 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 15672 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 15673 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 15674 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15675 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15676 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15677 | |
| 15678 | MockRead reads1[] = { |
| 15679 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 15680 | }; |
| 15681 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15682 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15683 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15684 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15685 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15686 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15687 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15688 | }; |
| 15689 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15690 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15691 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15692 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15693 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 15694 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15695 | }; |
| 15696 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15697 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15698 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15699 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15700 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15701 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15702 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15703 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15704 | |
| 15705 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15706 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15707 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15708 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15709 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15710 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15711 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15712 | |
| 15713 | // Start the first transaction to set up the SpdySession and verify that |
| 15714 | // connection was closed. |
| 15715 | HttpRequestInfo request1; |
| 15716 | request1.method = "GET"; |
| 15717 | request1.url = GURL(https_url); |
| 15718 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15719 | request1.traffic_annotation = |
| 15720 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15721 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15722 | TestCompletionCallback callback1; |
| 15723 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15724 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15725 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15726 | |
| 15727 | // Now, start the second request and make sure it succeeds. |
| 15728 | HttpRequestInfo request2; |
| 15729 | request2.method = "GET"; |
| 15730 | request2.url = GURL(https_url); |
| 15731 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 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] | 85f9734 | 2013-04-17 06:12:24 | [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())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15738 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15739 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15740 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15741 | } |
| 15742 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15743 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15744 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15745 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15746 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15747 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15748 | |
| 15749 | // Use two different hosts with different IPs so they don't get pooled. |
| 15750 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 15751 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15753 | |
| 15754 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15755 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15756 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15757 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15758 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15759 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15760 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15761 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15762 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15763 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15764 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15765 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15766 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15767 | SpdySerializedFrame host1_resp_body( |
| 15768 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15769 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15770 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15771 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15772 | }; |
| 15773 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15774 | // Use a separate test instance for the separate SpdySession that will be |
| 15775 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15776 | SpdyTestUtil spdy_util_2; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15777 | auto spdy1_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15778 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 15779 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15780 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 15781 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15782 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15783 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15784 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15785 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15786 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15787 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15788 | SpdySerializedFrame host2_resp_body( |
| 15789 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15790 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15791 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15792 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15793 | }; |
| 15794 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15795 | auto spdy2_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15796 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 15797 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15798 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 15799 | |
| 15800 | MockWrite http_write[] = { |
| 15801 | MockWrite("GET / HTTP/1.1\r\n" |
| 15802 | "Host: www.a.com\r\n" |
| 15803 | "Connection: keep-alive\r\n\r\n"), |
| 15804 | }; |
| 15805 | |
| 15806 | MockRead http_read[] = { |
| 15807 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15808 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15809 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15810 | MockRead("hello!"), |
| 15811 | }; |
| 15812 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 15813 | http_write, arraysize(http_write)); |
| 15814 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15815 | |
| 15816 | HostPortPair host_port_pair_a("www.a.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15817 | SpdySessionKey spdy_session_key_a(host_port_pair_a, ProxyServer::Direct(), |
| 15818 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15819 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15820 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15821 | |
| 15822 | TestCompletionCallback callback; |
| 15823 | HttpRequestInfo request1; |
| 15824 | request1.method = "GET"; |
| 15825 | request1.url = GURL("https://www.a.com/"); |
| 15826 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15827 | request1.traffic_annotation = |
| 15828 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15829 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15830 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15831 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15832 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15833 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15834 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15835 | |
| 15836 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15837 | ASSERT_TRUE(response); |
| 15838 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15839 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15840 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15841 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15842 | |
| 15843 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15844 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15845 | EXPECT_EQ("hello!", response_data); |
| 15846 | trans.reset(); |
| 15847 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15848 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15849 | |
| 15850 | HostPortPair host_port_pair_b("www.b.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15851 | SpdySessionKey spdy_session_key_b(host_port_pair_b, ProxyServer::Direct(), |
| 15852 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15853 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15854 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15855 | HttpRequestInfo request2; |
| 15856 | request2.method = "GET"; |
| 15857 | request2.url = GURL("https://www.b.com/"); |
| 15858 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15859 | request2.traffic_annotation = |
| 15860 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15861 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15862 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15863 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15864 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15866 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15867 | |
| 15868 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15869 | ASSERT_TRUE(response); |
| 15870 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15871 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15872 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15873 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15874 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15875 | EXPECT_EQ("hello!", response_data); |
| 15876 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15877 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15878 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15879 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15880 | |
| 15881 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15882 | SpdySessionKey spdy_session_key_a1(host_port_pair_a1, ProxyServer::Direct(), |
| 15883 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15884 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15885 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15886 | HttpRequestInfo request3; |
| 15887 | request3.method = "GET"; |
| 15888 | request3.url = GURL("http://www.a.com/"); |
| 15889 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15890 | request3.traffic_annotation = |
| 15891 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15892 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15893 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15894 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15895 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15897 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15898 | |
| 15899 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15900 | ASSERT_TRUE(response); |
| 15901 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15902 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15903 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15904 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15905 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15906 | EXPECT_EQ("hello!", response_data); |
| 15907 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15908 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15909 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15910 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15911 | } |
| 15912 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15913 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15914 | HttpRequestInfo request; |
| 15915 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15916 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15917 | request.traffic_annotation = |
| 15918 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15919 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15920 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15921 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15922 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15923 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15924 | StaticSocketDataProvider data; |
| 15925 | data.set_connect_data(mock_connect); |
| 15926 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15927 | |
| 15928 | TestCompletionCallback callback; |
| 15929 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15930 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15932 | |
| 15933 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15934 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15935 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15936 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15937 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15938 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15939 | |
| 15940 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15941 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15942 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15943 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15944 | |
| 15945 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15946 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15947 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15948 | } |
| 15949 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15950 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15951 | HttpRequestInfo request; |
| 15952 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15953 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15954 | request.traffic_annotation = |
| 15955 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15956 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15957 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15958 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15959 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15960 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15961 | StaticSocketDataProvider data; |
| 15962 | data.set_connect_data(mock_connect); |
| 15963 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15964 | |
| 15965 | TestCompletionCallback callback; |
| 15966 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15967 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15968 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15969 | |
| 15970 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15971 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15972 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15973 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15974 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15975 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15976 | |
| 15977 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15978 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15979 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15980 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15981 | |
| 15982 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15983 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15984 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15985 | } |
| 15986 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15987 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15988 | HttpRequestInfo request; |
| 15989 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15990 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15991 | request.traffic_annotation = |
| 15992 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15993 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15994 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15995 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15996 | |
| 15997 | MockWrite data_writes[] = { |
| 15998 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15999 | }; |
| 16000 | MockRead data_reads[] = { |
| 16001 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16002 | }; |
| 16003 | |
| 16004 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16005 | data_writes, arraysize(data_writes)); |
| 16006 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16007 | |
| 16008 | TestCompletionCallback callback; |
| 16009 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16010 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16011 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16012 | |
| 16013 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16014 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16015 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16016 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16017 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16018 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16019 | } |
| 16020 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16021 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16022 | HttpRequestInfo request; |
| 16023 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16024 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16025 | request.traffic_annotation = |
| 16026 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16027 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16029 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16030 | |
| 16031 | MockWrite data_writes[] = { |
| 16032 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16033 | }; |
| 16034 | MockRead data_reads[] = { |
| 16035 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16036 | }; |
| 16037 | |
| 16038 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16039 | data_writes, arraysize(data_writes)); |
| 16040 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16041 | |
| 16042 | TestCompletionCallback callback; |
| 16043 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16044 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16045 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16046 | |
| 16047 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16048 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16049 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16050 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16051 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16052 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16053 | } |
| 16054 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16055 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16056 | HttpRequestInfo request; |
| 16057 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16058 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16059 | request.traffic_annotation = |
| 16060 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16061 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16062 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16063 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16064 | |
| 16065 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16066 | MockWrite( |
| 16067 | "GET / HTTP/1.1\r\n" |
| 16068 | "Host: www.example.org\r\n" |
| 16069 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16070 | }; |
| 16071 | MockRead data_reads[] = { |
| 16072 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16073 | }; |
| 16074 | |
| 16075 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16076 | data_writes, arraysize(data_writes)); |
| 16077 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16078 | |
| 16079 | TestCompletionCallback callback; |
| 16080 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16081 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16082 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16083 | |
| 16084 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16085 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16086 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16087 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16088 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16089 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16090 | } |
| 16091 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16092 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16093 | HttpRequestInfo request; |
| 16094 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16095 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16096 | request.traffic_annotation = |
| 16097 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16098 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16099 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16100 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16101 | |
| 16102 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16103 | MockWrite( |
| 16104 | "GET / HTTP/1.1\r\n" |
| 16105 | "Host: www.example.org\r\n" |
| 16106 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16107 | }; |
| 16108 | MockRead data_reads[] = { |
| 16109 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16110 | }; |
| 16111 | |
| 16112 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16113 | data_writes, arraysize(data_writes)); |
| 16114 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16115 | |
| 16116 | TestCompletionCallback callback; |
| 16117 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16118 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16119 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16120 | |
| 16121 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16122 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16123 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16124 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16125 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16126 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16127 | } |
| 16128 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16129 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16130 | HttpRequestInfo request; |
| 16131 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16132 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16133 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16134 | request.traffic_annotation = |
| 16135 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16136 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16137 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16138 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16139 | |
| 16140 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16141 | MockWrite( |
| 16142 | "GET / HTTP/1.1\r\n" |
| 16143 | "Host: www.example.org\r\n" |
| 16144 | "Connection: keep-alive\r\n" |
| 16145 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16146 | }; |
| 16147 | MockRead data_reads[] = { |
| 16148 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16149 | "Content-Length: 5\r\n\r\n" |
| 16150 | "hello"), |
| 16151 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16152 | }; |
| 16153 | |
| 16154 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16155 | data_writes, arraysize(data_writes)); |
| 16156 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16157 | |
| 16158 | TestCompletionCallback callback; |
| 16159 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16160 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16161 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16162 | |
| 16163 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16164 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16165 | |
| 16166 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16167 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16168 | std::string foo; |
| 16169 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 16170 | EXPECT_EQ("bar", foo); |
| 16171 | } |
| 16172 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16173 | namespace { |
| 16174 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 16175 | // Fake HttpStream that simply records calls to SetPriority(). |
| 16176 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16177 | public base::SupportsWeakPtr<FakeStream> { |
| 16178 | public: |
| 16179 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16180 | ~FakeStream() override = default; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16181 | |
| 16182 | RequestPriority priority() const { return priority_; } |
| 16183 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16184 | int InitializeStream(const HttpRequestInfo* request_info, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 16185 | bool can_send_early, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16186 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16187 | const NetLogWithSource& net_log, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16188 | CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16189 | return ERR_IO_PENDING; |
| 16190 | } |
| 16191 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16192 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 16193 | HttpResponseInfo* response, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16194 | CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16195 | ADD_FAILURE(); |
| 16196 | return ERR_UNEXPECTED; |
| 16197 | } |
| 16198 | |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16199 | int ReadResponseHeaders(CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16200 | ADD_FAILURE(); |
| 16201 | return ERR_UNEXPECTED; |
| 16202 | } |
| 16203 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16204 | int ReadResponseBody(IOBuffer* buf, |
| 16205 | int buf_len, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16206 | CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16207 | ADD_FAILURE(); |
| 16208 | return ERR_UNEXPECTED; |
| 16209 | } |
| 16210 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16211 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16212 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16213 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16214 | ADD_FAILURE(); |
| 16215 | return false; |
| 16216 | } |
| 16217 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16218 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16219 | ADD_FAILURE(); |
| 16220 | return false; |
| 16221 | } |
| 16222 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16223 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16224 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 16225 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16226 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 16227 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 16228 | ADD_FAILURE(); |
| 16229 | return 0; |
| 16230 | } |
| 16231 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 16232 | int64_t GetTotalSentBytes() const override { |
| 16233 | ADD_FAILURE(); |
| 16234 | return 0; |
| 16235 | } |
| 16236 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16237 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16238 | ADD_FAILURE(); |
| 16239 | return false; |
| 16240 | } |
| 16241 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 16242 | bool GetAlternativeService( |
| 16243 | AlternativeService* alternative_service) const override { |
| 16244 | ADD_FAILURE(); |
| 16245 | return false; |
| 16246 | } |
| 16247 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16248 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 16249 | |
| 16250 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16251 | ADD_FAILURE(); |
| 16252 | } |
| 16253 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16254 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 16255 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 16256 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 16257 | TokenBindingType tb_type, |
| 16258 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16259 | ADD_FAILURE(); |
| 16260 | return ERR_NOT_IMPLEMENTED; |
| 16261 | } |
| 16262 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16263 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16264 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 16265 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 16266 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16267 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16268 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 16269 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 16270 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 16271 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 16272 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16273 | private: |
| 16274 | RequestPriority priority_; |
| 16275 | |
| 16276 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 16277 | }; |
| 16278 | |
| 16279 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 16280 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16281 | class FakeStreamRequest : public HttpStreamRequest, |
| 16282 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 16283 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16284 | FakeStreamRequest(RequestPriority priority, |
| 16285 | HttpStreamRequest::Delegate* delegate) |
| 16286 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16287 | delegate_(delegate), |
| 16288 | websocket_stream_create_helper_(NULL) {} |
| 16289 | |
| 16290 | FakeStreamRequest(RequestPriority priority, |
| 16291 | HttpStreamRequest::Delegate* delegate, |
| 16292 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 16293 | : priority_(priority), |
| 16294 | delegate_(delegate), |
| 16295 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16296 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16297 | ~FakeStreamRequest() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16298 | |
| 16299 | RequestPriority priority() const { return priority_; } |
| 16300 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16301 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 16302 | websocket_stream_create_helper() const { |
| 16303 | return websocket_stream_create_helper_; |
| 16304 | } |
| 16305 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16306 | // Create a new FakeStream and pass it to the request's |
| 16307 | // delegate. Returns a weak pointer to the FakeStream. |
| 16308 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16309 | auto fake_stream = std::make_unique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16310 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 16311 | // immediately delete |fake_stream|. |
| 16312 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 16313 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16314 | return weak_stream; |
| 16315 | } |
| 16316 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 16317 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16318 | ADD_FAILURE(); |
| 16319 | return ERR_UNEXPECTED; |
| 16320 | } |
| 16321 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16322 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16323 | ADD_FAILURE(); |
| 16324 | return LoadState(); |
| 16325 | } |
| 16326 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16327 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16328 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16329 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16330 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 16331 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16332 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16333 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16334 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16335 | const ConnectionAttempts& connection_attempts() const override { |
| 16336 | static ConnectionAttempts no_attempts; |
| 16337 | return no_attempts; |
| 16338 | } |
| 16339 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16340 | private: |
| 16341 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16342 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16343 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16344 | |
| 16345 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 16346 | }; |
| 16347 | |
| 16348 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 16349 | class FakeStreamFactory : public HttpStreamFactory { |
| 16350 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16351 | FakeStreamFactory() = default; |
| 16352 | ~FakeStreamFactory() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16353 | |
| 16354 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 16355 | // RequestStream() (which may be NULL if it was destroyed already). |
| 16356 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 16357 | return last_stream_request_; |
| 16358 | } |
| 16359 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16360 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 16361 | const HttpRequestInfo& info, |
| 16362 | RequestPriority priority, |
| 16363 | const SSLConfig& server_ssl_config, |
| 16364 | const SSLConfig& proxy_ssl_config, |
| 16365 | HttpStreamRequest::Delegate* delegate, |
| 16366 | bool enable_ip_based_pooling, |
| 16367 | bool enable_alternative_services, |
| 16368 | const NetLogWithSource& net_log) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16369 | auto fake_request = std::make_unique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16370 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16371 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16372 | } |
| 16373 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16374 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 16375 | const HttpRequestInfo& info, |
| 16376 | RequestPriority priority, |
| 16377 | const SSLConfig& server_ssl_config, |
| 16378 | const SSLConfig& proxy_ssl_config, |
| 16379 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16380 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 16381 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16382 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 16383 | NOTREACHED(); |
| 16384 | return nullptr; |
| 16385 | } |
| 16386 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16387 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16388 | const HttpRequestInfo& info, |
| 16389 | RequestPriority priority, |
| 16390 | const SSLConfig& server_ssl_config, |
| 16391 | const SSLConfig& proxy_ssl_config, |
| 16392 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 16393 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16394 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 16395 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16396 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16397 | auto fake_request = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16398 | std::make_unique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16399 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16400 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16401 | } |
| 16402 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16403 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16404 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16405 | ADD_FAILURE(); |
| 16406 | } |
| 16407 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16408 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16409 | ADD_FAILURE(); |
| 16410 | return NULL; |
| 16411 | } |
| 16412 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 16413 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 16414 | const std::string& parent_absolute_name) const override { |
| 16415 | ADD_FAILURE(); |
| 16416 | } |
| 16417 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16418 | private: |
| 16419 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 16420 | |
| 16421 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 16422 | }; |
| 16423 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16424 | } // namespace |
| 16425 | |
| 16426 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 16427 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16428 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16430 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16431 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16432 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16433 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16434 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16435 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16436 | |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16437 | request.traffic_annotation = |
| 16438 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16439 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16440 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16441 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16442 | TestCompletionCallback callback; |
| 16443 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16444 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16445 | |
| 16446 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16447 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16448 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16449 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16450 | } |
| 16451 | |
| 16452 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16453 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16454 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16455 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16456 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16457 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16458 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16459 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16460 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16461 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16462 | |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16463 | request.traffic_annotation = |
| 16464 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16465 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16466 | TestCompletionCallback callback; |
| 16467 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16468 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16469 | |
| 16470 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16471 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16472 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16473 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16474 | |
| 16475 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16476 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16477 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 16478 | } |
| 16479 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16480 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16481 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16482 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16483 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16484 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16485 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16486 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16487 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16488 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16489 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16490 | |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16491 | request.traffic_annotation = |
| 16492 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16493 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16494 | TestCompletionCallback callback; |
| 16495 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16496 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16497 | |
| 16498 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16499 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16500 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16501 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16502 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16503 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 16504 | |
| 16505 | trans.SetPriority(LOWEST); |
| 16506 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 16507 | } |
| 16508 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16509 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16510 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16511 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16512 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16513 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16514 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16515 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16516 | |
| 16517 | // Set up SSL request. |
| 16518 | |
| 16519 | HttpRequestInfo ssl_request; |
| 16520 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16521 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16522 | ssl_request.traffic_annotation = |
| 16523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16524 | |
| 16525 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16526 | MockWrite( |
| 16527 | "GET / HTTP/1.1\r\n" |
| 16528 | "Host: www.example.org\r\n" |
| 16529 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16530 | }; |
| 16531 | MockRead ssl_reads[] = { |
| 16532 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16533 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16534 | MockRead("hello world"), |
| 16535 | MockRead(SYNCHRONOUS, OK), |
| 16536 | }; |
| 16537 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 16538 | ssl_writes, arraysize(ssl_writes)); |
| 16539 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16540 | |
| 16541 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16542 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16543 | |
| 16544 | // Set up HTTP request. |
| 16545 | |
| 16546 | HttpRequestInfo http_request; |
| 16547 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16548 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16549 | http_request.traffic_annotation = |
| 16550 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16551 | |
| 16552 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16553 | MockWrite( |
| 16554 | "GET / HTTP/1.1\r\n" |
| 16555 | "Host: www.example.org\r\n" |
| 16556 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16557 | }; |
| 16558 | MockRead http_reads[] = { |
| 16559 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16560 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16561 | MockRead("falafel"), |
| 16562 | MockRead(SYNCHRONOUS, OK), |
| 16563 | }; |
| 16564 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16565 | http_writes, arraysize(http_writes)); |
| 16566 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16567 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16569 | |
| 16570 | // Start the SSL request. |
| 16571 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16572 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16573 | ASSERT_EQ(ERR_IO_PENDING, |
| 16574 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 16575 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16576 | |
| 16577 | // Start the HTTP request. Pool should stall. |
| 16578 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16579 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16580 | ASSERT_EQ(ERR_IO_PENDING, |
| 16581 | http_trans.Start(&http_request, http_callback.callback(), |
| 16582 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16583 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16584 | |
| 16585 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16586 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16587 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16588 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16589 | EXPECT_EQ("hello world", response_data); |
| 16590 | |
| 16591 | // The SSL socket should automatically be closed, so the HTTP request can |
| 16592 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16593 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 16594 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16595 | |
| 16596 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16597 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16598 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16599 | EXPECT_EQ("falafel", response_data); |
| 16600 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16601 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16602 | } |
| 16603 | |
| 16604 | // Tests that when a SSL connection is established but there's no corresponding |
| 16605 | // request that needs it, the new socket is closed if the transport socket pool |
| 16606 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16607 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16608 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16609 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16610 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16611 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16612 | |
| 16613 | // Set up an ssl request. |
| 16614 | |
| 16615 | HttpRequestInfo ssl_request; |
| 16616 | ssl_request.method = "GET"; |
| 16617 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16618 | ssl_request.traffic_annotation = |
| 16619 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16620 | |
| 16621 | // No data will be sent on the SSL socket. |
| 16622 | StaticSocketDataProvider ssl_data; |
| 16623 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16624 | |
| 16625 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16626 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16627 | |
| 16628 | // Set up HTTP request. |
| 16629 | |
| 16630 | HttpRequestInfo http_request; |
| 16631 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16632 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16633 | http_request.traffic_annotation = |
| 16634 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16635 | |
| 16636 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16637 | MockWrite( |
| 16638 | "GET / HTTP/1.1\r\n" |
| 16639 | "Host: www.example.org\r\n" |
| 16640 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16641 | }; |
| 16642 | MockRead http_reads[] = { |
| 16643 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16644 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16645 | MockRead("falafel"), |
| 16646 | MockRead(SYNCHRONOUS, OK), |
| 16647 | }; |
| 16648 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16649 | http_writes, arraysize(http_writes)); |
| 16650 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16651 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16652 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16653 | |
| 16654 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 16655 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16656 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16657 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16658 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16659 | |
| 16660 | // Start the HTTP request. Pool should stall. |
| 16661 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16662 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16663 | ASSERT_EQ(ERR_IO_PENDING, |
| 16664 | http_trans.Start(&http_request, http_callback.callback(), |
| 16665 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16666 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16667 | |
| 16668 | // The SSL connection will automatically be closed once the connection is |
| 16669 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16670 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16671 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16672 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16673 | EXPECT_EQ("falafel", response_data); |
| 16674 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16675 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16676 | } |
| 16677 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16678 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16679 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16680 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16681 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16682 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16683 | |
| 16684 | HttpRequestInfo request; |
| 16685 | request.method = "POST"; |
| 16686 | request.url = GURL("http://www.foo.com/"); |
| 16687 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16688 | request.traffic_annotation = |
| 16689 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16690 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16691 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16692 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16693 | // Send headers successfully, but get an error while sending the body. |
| 16694 | MockWrite data_writes[] = { |
| 16695 | MockWrite("POST / HTTP/1.1\r\n" |
| 16696 | "Host: www.foo.com\r\n" |
| 16697 | "Connection: keep-alive\r\n" |
| 16698 | "Content-Length: 3\r\n\r\n"), |
| 16699 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16700 | }; |
| 16701 | |
| 16702 | MockRead data_reads[] = { |
| 16703 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16704 | MockRead("hello world"), |
| 16705 | MockRead(SYNCHRONOUS, OK), |
| 16706 | }; |
| 16707 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16708 | arraysize(data_writes)); |
| 16709 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16710 | |
| 16711 | TestCompletionCallback callback; |
| 16712 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16713 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16714 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16715 | |
| 16716 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16717 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16718 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16719 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16720 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16721 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16722 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16723 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16724 | |
| 16725 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16726 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16727 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16728 | EXPECT_EQ("hello world", response_data); |
| 16729 | } |
| 16730 | |
| 16731 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16732 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16733 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16734 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16735 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16736 | MockWrite data_writes[] = { |
| 16737 | MockWrite("GET / HTTP/1.1\r\n" |
| 16738 | "Host: www.foo.com\r\n" |
| 16739 | "Connection: keep-alive\r\n\r\n"), |
| 16740 | MockWrite("POST / HTTP/1.1\r\n" |
| 16741 | "Host: www.foo.com\r\n" |
| 16742 | "Connection: keep-alive\r\n" |
| 16743 | "Content-Length: 3\r\n\r\n"), |
| 16744 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16745 | }; |
| 16746 | |
| 16747 | MockRead data_reads[] = { |
| 16748 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16749 | "Content-Length: 14\r\n\r\n"), |
| 16750 | MockRead("first response"), |
| 16751 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16752 | "Content-Length: 15\r\n\r\n"), |
| 16753 | MockRead("second response"), |
| 16754 | MockRead(SYNCHRONOUS, OK), |
| 16755 | }; |
| 16756 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16757 | arraysize(data_writes)); |
| 16758 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16759 | |
| 16760 | TestCompletionCallback callback; |
| 16761 | HttpRequestInfo request1; |
| 16762 | request1.method = "GET"; |
| 16763 | request1.url = GURL("http://www.foo.com/"); |
| 16764 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16765 | request1.traffic_annotation = |
| 16766 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16767 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16768 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16769 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16770 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16771 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16772 | |
| 16773 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16774 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16775 | |
| 16776 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16777 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16778 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16779 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16780 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16781 | |
| 16782 | std::string response_data1; |
| 16783 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16784 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16785 | EXPECT_EQ("first response", response_data1); |
| 16786 | // Delete the transaction to release the socket back into the socket pool. |
| 16787 | trans1.reset(); |
| 16788 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16789 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16790 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16791 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16792 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16793 | |
| 16794 | HttpRequestInfo request2; |
| 16795 | request2.method = "POST"; |
| 16796 | request2.url = GURL("http://www.foo.com/"); |
| 16797 | request2.upload_data_stream = &upload_data_stream; |
| 16798 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16799 | request2.traffic_annotation = |
| 16800 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16801 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16802 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16803 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16804 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16805 | |
| 16806 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16807 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16808 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16809 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16810 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16811 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16812 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16813 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16814 | |
| 16815 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16816 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16817 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16818 | EXPECT_EQ("second response", response_data2); |
| 16819 | } |
| 16820 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16821 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16822 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16823 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16824 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16825 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16826 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16827 | |
| 16828 | HttpRequestInfo request; |
| 16829 | request.method = "POST"; |
| 16830 | request.url = GURL("http://www.foo.com/"); |
| 16831 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16832 | request.traffic_annotation = |
| 16833 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16834 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16835 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16836 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16837 | // Send headers successfully, but get an error while sending the body. |
| 16838 | MockWrite data_writes[] = { |
| 16839 | MockWrite("POST / HTTP/1.1\r\n" |
| 16840 | "Host: www.foo.com\r\n" |
| 16841 | "Connection: keep-alive\r\n" |
| 16842 | "Content-Length: 3\r\n\r\n" |
| 16843 | "fo"), |
| 16844 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16845 | }; |
| 16846 | |
| 16847 | MockRead data_reads[] = { |
| 16848 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16849 | MockRead("hello world"), |
| 16850 | MockRead(SYNCHRONOUS, OK), |
| 16851 | }; |
| 16852 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16853 | arraysize(data_writes)); |
| 16854 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16855 | |
| 16856 | TestCompletionCallback callback; |
| 16857 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16858 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16859 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16860 | |
| 16861 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16862 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16863 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16864 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16865 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16866 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16867 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16868 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16869 | |
| 16870 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16871 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16872 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16873 | EXPECT_EQ("hello world", response_data); |
| 16874 | } |
| 16875 | |
| 16876 | // This tests the more common case than the previous test, where headers and |
| 16877 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16878 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16879 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16880 | |
| 16881 | HttpRequestInfo request; |
| 16882 | request.method = "POST"; |
| 16883 | request.url = GURL("http://www.foo.com/"); |
| 16884 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16885 | request.traffic_annotation = |
| 16886 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16887 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16889 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16890 | // Send headers successfully, but get an error while sending the body. |
| 16891 | MockWrite data_writes[] = { |
| 16892 | MockWrite("POST / HTTP/1.1\r\n" |
| 16893 | "Host: www.foo.com\r\n" |
| 16894 | "Connection: keep-alive\r\n" |
| 16895 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16896 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16897 | }; |
| 16898 | |
| 16899 | MockRead data_reads[] = { |
| 16900 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16901 | MockRead("hello world"), |
| 16902 | MockRead(SYNCHRONOUS, OK), |
| 16903 | }; |
| 16904 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16905 | arraysize(data_writes)); |
| 16906 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16907 | |
| 16908 | TestCompletionCallback callback; |
| 16909 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16910 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16911 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16912 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16913 | // they can't be merged with the body in a single send. Not currently |
| 16914 | // necessary since a chunked body is never merged with headers, but this makes |
| 16915 | // the test more future proof. |
| 16916 | base::RunLoop().RunUntilIdle(); |
| 16917 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16918 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16919 | |
| 16920 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16921 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16922 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16923 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16924 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16925 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16926 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16927 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16928 | |
| 16929 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16930 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16931 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16932 | EXPECT_EQ("hello world", response_data); |
| 16933 | } |
| 16934 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16935 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16936 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16937 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16938 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16939 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16940 | |
| 16941 | HttpRequestInfo request; |
| 16942 | request.method = "POST"; |
| 16943 | request.url = GURL("http://www.foo.com/"); |
| 16944 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16945 | request.traffic_annotation = |
| 16946 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16947 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16948 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16949 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16950 | |
| 16951 | MockWrite data_writes[] = { |
| 16952 | MockWrite("POST / HTTP/1.1\r\n" |
| 16953 | "Host: www.foo.com\r\n" |
| 16954 | "Connection: keep-alive\r\n" |
| 16955 | "Content-Length: 3\r\n\r\n"), |
| 16956 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16957 | }; |
| 16958 | |
| 16959 | MockRead data_reads[] = { |
| 16960 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16961 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16962 | MockRead("hello world"), |
| 16963 | MockRead(SYNCHRONOUS, OK), |
| 16964 | }; |
| 16965 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16966 | arraysize(data_writes)); |
| 16967 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16968 | |
| 16969 | TestCompletionCallback callback; |
| 16970 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16971 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16972 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16973 | |
| 16974 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16975 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16976 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16977 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16978 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16979 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16980 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16981 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16982 | |
| 16983 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16984 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16985 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16986 | EXPECT_EQ("hello world", response_data); |
| 16987 | } |
| 16988 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16989 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16990 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16991 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16992 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16993 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16994 | |
| 16995 | HttpRequestInfo request; |
| 16996 | request.method = "POST"; |
| 16997 | request.url = GURL("http://www.foo.com/"); |
| 16998 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16999 | request.traffic_annotation = |
| 17000 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17001 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17002 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17003 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17004 | // Send headers successfully, but get an error while sending the body. |
| 17005 | MockWrite data_writes[] = { |
| 17006 | MockWrite("POST / HTTP/1.1\r\n" |
| 17007 | "Host: www.foo.com\r\n" |
| 17008 | "Connection: keep-alive\r\n" |
| 17009 | "Content-Length: 3\r\n\r\n"), |
| 17010 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17011 | }; |
| 17012 | |
| 17013 | MockRead data_reads[] = { |
| 17014 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17015 | MockRead("hello world"), |
| 17016 | MockRead(SYNCHRONOUS, OK), |
| 17017 | }; |
| 17018 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17019 | arraysize(data_writes)); |
| 17020 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17021 | |
| 17022 | TestCompletionCallback callback; |
| 17023 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17024 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17025 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17026 | |
| 17027 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17028 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17029 | } |
| 17030 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17031 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17032 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17033 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17034 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17035 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17036 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17037 | |
| 17038 | HttpRequestInfo request; |
| 17039 | request.method = "POST"; |
| 17040 | request.url = GURL("http://www.foo.com/"); |
| 17041 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17042 | request.traffic_annotation = |
| 17043 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17044 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17045 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17046 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17047 | // Send headers successfully, but get an error while sending the body. |
| 17048 | MockWrite data_writes[] = { |
| 17049 | MockWrite("POST / HTTP/1.1\r\n" |
| 17050 | "Host: www.foo.com\r\n" |
| 17051 | "Connection: keep-alive\r\n" |
| 17052 | "Content-Length: 3\r\n\r\n"), |
| 17053 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17054 | }; |
| 17055 | |
| 17056 | MockRead data_reads[] = { |
| 17057 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17058 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17059 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17060 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17061 | MockRead(SYNCHRONOUS, OK), |
| 17062 | }; |
| 17063 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17064 | arraysize(data_writes)); |
| 17065 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17066 | |
| 17067 | TestCompletionCallback callback; |
| 17068 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17069 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17070 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17071 | |
| 17072 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17073 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17074 | } |
| 17075 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17076 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17077 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17078 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17079 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17080 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17081 | |
| 17082 | HttpRequestInfo request; |
| 17083 | request.method = "POST"; |
| 17084 | request.url = GURL("http://www.foo.com/"); |
| 17085 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17086 | request.traffic_annotation = |
| 17087 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17088 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17089 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17090 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17091 | // Send headers successfully, but get an error while sending the body. |
| 17092 | MockWrite data_writes[] = { |
| 17093 | MockWrite("POST / HTTP/1.1\r\n" |
| 17094 | "Host: www.foo.com\r\n" |
| 17095 | "Connection: keep-alive\r\n" |
| 17096 | "Content-Length: 3\r\n\r\n"), |
| 17097 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17098 | }; |
| 17099 | |
| 17100 | MockRead data_reads[] = { |
| 17101 | MockRead("HTTP 0.9 rocks!"), |
| 17102 | MockRead(SYNCHRONOUS, OK), |
| 17103 | }; |
| 17104 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17105 | arraysize(data_writes)); |
| 17106 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17107 | |
| 17108 | TestCompletionCallback callback; |
| 17109 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17110 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17111 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17112 | |
| 17113 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17114 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17115 | } |
| 17116 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17117 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17118 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17119 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17120 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17121 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17122 | |
| 17123 | HttpRequestInfo request; |
| 17124 | request.method = "POST"; |
| 17125 | request.url = GURL("http://www.foo.com/"); |
| 17126 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17127 | request.traffic_annotation = |
| 17128 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17129 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17130 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17131 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17132 | // Send headers successfully, but get an error while sending the body. |
| 17133 | MockWrite data_writes[] = { |
| 17134 | MockWrite("POST / HTTP/1.1\r\n" |
| 17135 | "Host: www.foo.com\r\n" |
| 17136 | "Connection: keep-alive\r\n" |
| 17137 | "Content-Length: 3\r\n\r\n"), |
| 17138 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17139 | }; |
| 17140 | |
| 17141 | MockRead data_reads[] = { |
| 17142 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17143 | MockRead(SYNCHRONOUS, OK), |
| 17144 | }; |
| 17145 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17146 | arraysize(data_writes)); |
| 17147 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17148 | |
| 17149 | TestCompletionCallback callback; |
| 17150 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17151 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17152 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17153 | |
| 17154 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17155 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17156 | } |
| 17157 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17158 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17159 | |
| 17160 | namespace { |
| 17161 | |
| 17162 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17163 | headers->SetHeader("Connection", "Upgrade"); |
| 17164 | headers->SetHeader("Upgrade", "websocket"); |
| 17165 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17166 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17167 | } |
| 17168 | |
| 17169 | } // namespace |
| 17170 | |
| 17171 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 17172 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 17173 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 17174 | // that the different schemes work. |
| 17175 | std::string test_cases[] = {"ws://www.example.org/", |
| 17176 | "wss://www.example.org/"}; |
| 17177 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 17178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17179 | HttpNetworkSessionPeer peer(session.get()); |
| 17180 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 17181 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
| 17182 | |
| 17183 | HttpRequestInfo request; |
| 17184 | request.method = "GET"; |
| 17185 | request.url = GURL(test_cases[i]); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17186 | request.traffic_annotation = |
| 17187 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17188 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17189 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17190 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17191 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17192 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 17193 | &websocket_stream_create_helper); |
| 17194 | |
| 17195 | TestCompletionCallback callback; |
| 17196 | EXPECT_EQ(ERR_IO_PENDING, |
| 17197 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 17198 | |
| 17199 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 17200 | fake_factory->last_stream_request(); |
| 17201 | ASSERT_TRUE(fake_request); |
| 17202 | EXPECT_EQ(&websocket_stream_create_helper, |
| 17203 | fake_request->websocket_stream_create_helper()); |
| 17204 | } |
| 17205 | } |
| 17206 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17207 | // Verify that proxy headers are not sent to the destination server when |
| 17208 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17209 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17210 | HttpRequestInfo request; |
| 17211 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17212 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17213 | request.traffic_annotation = |
| 17214 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17215 | AddWebSocketHeaders(&request.extra_headers); |
| 17216 | |
| 17217 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17218 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17219 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17220 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17221 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17223 | |
| 17224 | // Since a proxy is configured, try to establish a tunnel. |
| 17225 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17226 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17227 | "Host: www.example.org:443\r\n" |
| 17228 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17229 | |
| 17230 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17231 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17232 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17233 | "Host: www.example.org:443\r\n" |
| 17234 | "Proxy-Connection: keep-alive\r\n" |
| 17235 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17236 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17237 | MockWrite("GET / HTTP/1.1\r\n" |
| 17238 | "Host: www.example.org\r\n" |
| 17239 | "Connection: Upgrade\r\n" |
| 17240 | "Upgrade: websocket\r\n" |
| 17241 | "Origin: http://www.example.org\r\n" |
| 17242 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17243 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17244 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17245 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17246 | |
| 17247 | // The proxy responds to the connect with a 407, using a persistent |
| 17248 | // connection. |
| 17249 | MockRead data_reads[] = { |
| 17250 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17251 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17252 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17253 | "Content-Length: 0\r\n" |
| 17254 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17255 | |
| 17256 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17257 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17258 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17259 | "Upgrade: websocket\r\n" |
| 17260 | "Connection: Upgrade\r\n" |
| 17261 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17262 | |
| 17263 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17264 | arraysize(data_writes)); |
| 17265 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17266 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17267 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17268 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17269 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17270 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17271 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17272 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17273 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17274 | &websocket_stream_create_helper); |
| 17275 | |
| 17276 | { |
| 17277 | TestCompletionCallback callback; |
| 17278 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17279 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17280 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17281 | |
| 17282 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17283 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17284 | } |
| 17285 | |
| 17286 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17287 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17288 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17289 | EXPECT_EQ(407, response->headers->response_code()); |
| 17290 | |
| 17291 | { |
| 17292 | TestCompletionCallback callback; |
| 17293 | |
| 17294 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17295 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17296 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17297 | |
| 17298 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17299 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17300 | } |
| 17301 | |
| 17302 | response = trans->GetResponseInfo(); |
| 17303 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17304 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17305 | |
| 17306 | EXPECT_EQ(101, response->headers->response_code()); |
| 17307 | |
| 17308 | trans.reset(); |
| 17309 | session->CloseAllConnections(); |
| 17310 | } |
| 17311 | |
| 17312 | // Verify that proxy headers are not sent to the destination server when |
| 17313 | // establishing a tunnel for an insecure WebSocket connection. |
| 17314 | // This requires the authentication info to be injected into the auth cache |
| 17315 | // due to crbug.com/395064 |
| 17316 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17317 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17318 | HttpRequestInfo request; |
| 17319 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17320 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17321 | request.traffic_annotation = |
| 17322 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17323 | AddWebSocketHeaders(&request.extra_headers); |
| 17324 | |
| 17325 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17326 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17327 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17328 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17329 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17330 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17331 | |
| 17332 | MockWrite data_writes[] = { |
| 17333 | // Try to establish a tunnel for the WebSocket connection, with |
| 17334 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17335 | // they cannot and will not use the same TCP/IP connection as the |
| 17336 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17337 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17338 | "Host: www.example.org:80\r\n" |
| 17339 | "Proxy-Connection: keep-alive\r\n" |
| 17340 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17341 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17342 | MockWrite("GET / HTTP/1.1\r\n" |
| 17343 | "Host: www.example.org\r\n" |
| 17344 | "Connection: Upgrade\r\n" |
| 17345 | "Upgrade: websocket\r\n" |
| 17346 | "Origin: http://www.example.org\r\n" |
| 17347 | "Sec-WebSocket-Version: 13\r\n" |
| 17348 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17349 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17350 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17351 | |
| 17352 | MockRead data_reads[] = { |
| 17353 | // HTTP CONNECT with credentials. |
| 17354 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17355 | |
| 17356 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17357 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17358 | "Upgrade: websocket\r\n" |
| 17359 | "Connection: Upgrade\r\n" |
| 17360 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17361 | |
| 17362 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17363 | arraysize(data_writes)); |
| 17364 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17365 | |
| 17366 | session->http_auth_cache()->Add( |
| 17367 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17368 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17369 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17370 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17371 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17372 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17373 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17374 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17375 | &websocket_stream_create_helper); |
| 17376 | |
| 17377 | TestCompletionCallback callback; |
| 17378 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17379 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17380 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17381 | |
| 17382 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17383 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17384 | |
| 17385 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17386 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17387 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17388 | |
| 17389 | EXPECT_EQ(101, response->headers->response_code()); |
| 17390 | |
| 17391 | trans.reset(); |
| 17392 | session->CloseAllConnections(); |
| 17393 | } |
| 17394 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17395 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17396 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17397 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17398 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17399 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17400 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17401 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17402 | |
| 17403 | HttpRequestInfo request; |
| 17404 | request.method = "POST"; |
| 17405 | request.url = GURL("http://www.foo.com/"); |
| 17406 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17407 | request.traffic_annotation = |
| 17408 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17409 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17410 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17411 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17412 | MockWrite data_writes[] = { |
| 17413 | MockWrite("POST / HTTP/1.1\r\n" |
| 17414 | "Host: www.foo.com\r\n" |
| 17415 | "Connection: keep-alive\r\n" |
| 17416 | "Content-Length: 3\r\n\r\n"), |
| 17417 | MockWrite("foo"), |
| 17418 | }; |
| 17419 | |
| 17420 | MockRead data_reads[] = { |
| 17421 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17422 | MockRead(SYNCHRONOUS, OK), |
| 17423 | }; |
| 17424 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17425 | arraysize(data_writes)); |
| 17426 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17427 | |
| 17428 | TestCompletionCallback callback; |
| 17429 | |
| 17430 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17431 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17432 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17433 | |
| 17434 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17435 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17436 | |
| 17437 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17438 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17439 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17440 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17441 | } |
| 17442 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17443 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17444 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17445 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17446 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17447 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17448 | |
| 17449 | HttpRequestInfo request; |
| 17450 | request.method = "POST"; |
| 17451 | request.url = GURL("http://www.foo.com/"); |
| 17452 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17453 | request.traffic_annotation = |
| 17454 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17455 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17456 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17457 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17458 | MockWrite data_writes[] = { |
| 17459 | MockWrite("POST / HTTP/1.1\r\n" |
| 17460 | "Host: www.foo.com\r\n" |
| 17461 | "Connection: keep-alive\r\n" |
| 17462 | "Content-Length: 3\r\n\r\n"), |
| 17463 | MockWrite("foo"), |
| 17464 | }; |
| 17465 | |
| 17466 | MockRead data_reads[] = { |
| 17467 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17468 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17469 | MockRead(SYNCHRONOUS, OK), |
| 17470 | }; |
| 17471 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17472 | arraysize(data_writes)); |
| 17473 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17474 | |
| 17475 | TestCompletionCallback callback; |
| 17476 | |
| 17477 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17478 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17479 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17480 | |
| 17481 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17482 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17483 | |
| 17484 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17485 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17486 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17487 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17488 | } |
| 17489 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17490 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17491 | ChunkedUploadDataStream upload_data_stream(0); |
| 17492 | |
| 17493 | HttpRequestInfo request; |
| 17494 | request.method = "POST"; |
| 17495 | request.url = GURL("http://www.foo.com/"); |
| 17496 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17497 | request.traffic_annotation = |
| 17498 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17499 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17500 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17501 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17502 | // Send headers successfully, but get an error while sending the body. |
| 17503 | MockWrite data_writes[] = { |
| 17504 | MockWrite("POST / HTTP/1.1\r\n" |
| 17505 | "Host: www.foo.com\r\n" |
| 17506 | "Connection: keep-alive\r\n" |
| 17507 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17508 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17509 | }; |
| 17510 | |
| 17511 | MockRead data_reads[] = { |
| 17512 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17513 | MockRead(SYNCHRONOUS, OK), |
| 17514 | }; |
| 17515 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17516 | arraysize(data_writes)); |
| 17517 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17518 | |
| 17519 | TestCompletionCallback callback; |
| 17520 | |
| 17521 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17522 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17523 | |
| 17524 | base::RunLoop().RunUntilIdle(); |
| 17525 | upload_data_stream.AppendData("f", 1, false); |
| 17526 | |
| 17527 | base::RunLoop().RunUntilIdle(); |
| 17528 | upload_data_stream.AppendData("oo", 2, true); |
| 17529 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17530 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17531 | |
| 17532 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17533 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17534 | |
| 17535 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17536 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17537 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17538 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17539 | } |
| 17540 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17541 | // Confirm that transactions whose throttle is created in (and stays in) |
| 17542 | // the unthrottled state are not blocked. |
| 17543 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 17544 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17545 | std::unique_ptr<HttpNetworkSession> session( |
| 17546 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17547 | |
| 17548 | // Send a simple request and make sure it goes through. |
| 17549 | HttpRequestInfo request; |
| 17550 | request.method = "GET"; |
| 17551 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17552 | request.traffic_annotation = |
| 17553 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17554 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17555 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17556 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17557 | |
| 17558 | MockWrite data_writes[] = { |
| 17559 | MockWrite("GET / HTTP/1.1\r\n" |
| 17560 | "Host: www.example.org\r\n" |
| 17561 | "Connection: keep-alive\r\n\r\n"), |
| 17562 | }; |
| 17563 | MockRead data_reads[] = { |
| 17564 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17565 | MockRead(SYNCHRONOUS, OK), |
| 17566 | }; |
| 17567 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17568 | arraysize(data_writes)); |
| 17569 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17570 | |
| 17571 | TestCompletionCallback callback; |
| 17572 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17573 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17574 | } |
| 17575 | |
| 17576 | // Confirm requests can be blocked by a throttler, and are resumed |
| 17577 | // when the throttle is unblocked. |
| 17578 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 17579 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17580 | std::unique_ptr<HttpNetworkSession> session( |
| 17581 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17582 | |
| 17583 | // Send a simple request and make sure it goes through. |
| 17584 | HttpRequestInfo request; |
| 17585 | request.method = "GET"; |
| 17586 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17587 | request.traffic_annotation = |
| 17588 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17589 | |
| 17590 | MockWrite data_writes[] = { |
| 17591 | MockWrite("GET / HTTP/1.1\r\n" |
| 17592 | "Host: www.example.org\r\n" |
| 17593 | "Connection: keep-alive\r\n\r\n"), |
| 17594 | }; |
| 17595 | MockRead data_reads[] = { |
| 17596 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17597 | MockRead(SYNCHRONOUS, OK), |
| 17598 | }; |
| 17599 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17600 | arraysize(data_writes)); |
| 17601 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17602 | |
| 17603 | // Start a request that will be throttled at start; confirm it |
| 17604 | // doesn't complete. |
| 17605 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17606 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17607 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17608 | |
| 17609 | TestCompletionCallback callback; |
| 17610 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17611 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17612 | |
| 17613 | base::RunLoop().RunUntilIdle(); |
| 17614 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17615 | EXPECT_FALSE(callback.have_result()); |
| 17616 | |
| 17617 | // Confirm the request goes on to complete when unthrottled. |
| 17618 | throttler->UnthrottleAllRequests(); |
| 17619 | base::RunLoop().RunUntilIdle(); |
| 17620 | ASSERT_TRUE(callback.have_result()); |
| 17621 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17622 | } |
| 17623 | |
| 17624 | // Destroy a request while it's throttled. |
| 17625 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 17626 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17627 | std::unique_ptr<HttpNetworkSession> session( |
| 17628 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17629 | |
| 17630 | // Send a simple request and make sure it goes through. |
| 17631 | HttpRequestInfo request; |
| 17632 | request.method = "GET"; |
| 17633 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17634 | request.traffic_annotation = |
| 17635 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17636 | |
| 17637 | MockWrite data_writes[] = { |
| 17638 | MockWrite("GET / HTTP/1.1\r\n" |
| 17639 | "Host: www.example.org\r\n" |
| 17640 | "Connection: keep-alive\r\n\r\n"), |
| 17641 | }; |
| 17642 | MockRead data_reads[] = { |
| 17643 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17644 | MockRead(SYNCHRONOUS, OK), |
| 17645 | }; |
| 17646 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17647 | arraysize(data_writes)); |
| 17648 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17649 | |
| 17650 | // Start a request that will be throttled at start; confirm it |
| 17651 | // doesn't complete. |
| 17652 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17653 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17654 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17655 | |
| 17656 | TestCompletionCallback callback; |
| 17657 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17658 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17659 | |
| 17660 | base::RunLoop().RunUntilIdle(); |
| 17661 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17662 | EXPECT_FALSE(callback.have_result()); |
| 17663 | |
| 17664 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 17665 | trans.reset(); |
| 17666 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 17667 | } |
| 17668 | |
| 17669 | // Confirm the throttler receives SetPriority calls. |
| 17670 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 17671 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17672 | std::unique_ptr<HttpNetworkSession> session( |
| 17673 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17674 | |
| 17675 | // Send a simple request and make sure it goes through. |
| 17676 | HttpRequestInfo request; |
| 17677 | request.method = "GET"; |
| 17678 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17679 | request.traffic_annotation = |
| 17680 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17681 | |
| 17682 | MockWrite data_writes[] = { |
| 17683 | MockWrite("GET / HTTP/1.1\r\n" |
| 17684 | "Host: www.example.org\r\n" |
| 17685 | "Connection: keep-alive\r\n\r\n"), |
| 17686 | }; |
| 17687 | MockRead data_reads[] = { |
| 17688 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17689 | MockRead(SYNCHRONOUS, OK), |
| 17690 | }; |
| 17691 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17692 | arraysize(data_writes)); |
| 17693 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17694 | |
| 17695 | throttler->set_throttle_new_requests(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17696 | auto trans = std::make_unique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17697 | // Start the transaction to associate a throttle with it. |
| 17698 | TestCompletionCallback callback; |
| 17699 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17700 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17701 | |
| 17702 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 17703 | trans->SetPriority(LOW); |
| 17704 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 17705 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 17706 | |
| 17707 | throttler->UnthrottleAllRequests(); |
| 17708 | base::RunLoop().RunUntilIdle(); |
| 17709 | ASSERT_TRUE(callback.have_result()); |
| 17710 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17711 | } |
| 17712 | |
| 17713 | // Confirm that unthrottling from a SetPriority call by the |
| 17714 | // throttler works properly. |
| 17715 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 17716 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17717 | std::unique_ptr<HttpNetworkSession> session( |
| 17718 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17719 | |
| 17720 | // Send a simple request and make sure it goes through. |
| 17721 | HttpRequestInfo request; |
| 17722 | request.method = "GET"; |
| 17723 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17724 | request.traffic_annotation = |
| 17725 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17726 | |
| 17727 | MockWrite data_writes[] = { |
| 17728 | MockWrite("GET / HTTP/1.1\r\n" |
| 17729 | "Host: www.example.org\r\n" |
| 17730 | "Connection: keep-alive\r\n\r\n"), |
| 17731 | }; |
| 17732 | MockRead data_reads[] = { |
| 17733 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17734 | MockRead(SYNCHRONOUS, OK), |
| 17735 | }; |
| 17736 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17737 | arraysize(data_writes)); |
| 17738 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17739 | |
| 17740 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17741 | data_writes, arraysize(data_writes)); |
| 17742 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17743 | |
| 17744 | // Start a request that will be throttled at start; confirm it |
| 17745 | // doesn't complete. |
| 17746 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17747 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17748 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17749 | |
| 17750 | TestCompletionCallback callback; |
| 17751 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17752 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17753 | |
| 17754 | base::RunLoop().RunUntilIdle(); |
| 17755 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17756 | EXPECT_FALSE(callback.have_result()); |
| 17757 | |
| 17758 | // Create a new request, call SetPriority on it to unthrottle, |
| 17759 | // and make sure that allows the original request to complete. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17760 | auto trans1 = std::make_unique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17761 | throttler->set_priority_change_closure( |
| 17762 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 17763 | base::Unretained(throttler))); |
| 17764 | |
| 17765 | // Start the transaction to associate a throttle with it. |
| 17766 | TestCompletionCallback callback1; |
| 17767 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 17768 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17769 | |
| 17770 | trans1->SetPriority(IDLE); |
| 17771 | |
| 17772 | base::RunLoop().RunUntilIdle(); |
| 17773 | ASSERT_TRUE(callback.have_result()); |
| 17774 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17775 | ASSERT_TRUE(callback1.have_result()); |
| 17776 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 17777 | } |
| 17778 | |
| 17779 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17780 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17781 | |
| 17782 | // Confirm that destroying a transaction from a SetPriority call by the |
| 17783 | // throttler works properly. |
| 17784 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 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 | b5e433e | 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 | // Arrange for the set priority call on the above transaction to delete |
| 17828 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17829 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17830 | throttler->set_priority_change_closure( |
| 17831 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 17832 | |
| 17833 | // Call it and check results (partially a "doesn't crash" test). |
| 17834 | trans_ptr->SetPriority(IDLE); |
| 17835 | trans_ptr = nullptr; // No longer a valid pointer. |
| 17836 | |
| 17837 | base::RunLoop().RunUntilIdle(); |
| 17838 | ASSERT_FALSE(callback.have_result()); |
| 17839 | } |
| 17840 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17841 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17842 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17843 | const std::string https_url = "https://www.example.com"; |
| 17844 | HttpRequestInfo request; |
| 17845 | request.url = GURL(https_url); |
| 17846 | request.method = "GET"; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17847 | request.traffic_annotation = |
| 17848 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17849 | |
| 17850 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17851 | ssl.ssl_info.token_binding_negotiated = true; |
| 17852 | ssl.ssl_info.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17853 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17854 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17855 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17856 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17857 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 17858 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17859 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 17860 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 17861 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17862 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17863 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17864 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17865 | |
| 17866 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17867 | TestCompletionCallback callback; |
| 17868 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17869 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17870 | |
| 17871 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17872 | |
| 17873 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17874 | HttpRequestHeaders headers; |
| 17875 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17876 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17877 | } |
| 17878 | #endif // !defined(OS_IOS) |
| 17879 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17880 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17881 | const std::string& accept_encoding, |
| 17882 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17883 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17884 | bool should_match) { |
| 17885 | HttpRequestInfo request; |
| 17886 | request.method = "GET"; |
| 17887 | request.url = GURL("http://www.foo.com/"); |
| 17888 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17889 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17890 | request.traffic_annotation = |
| 17891 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17892 | |
| 17893 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17894 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17895 | // Send headers successfully, but get an error while sending the body. |
| 17896 | MockWrite data_writes[] = { |
| 17897 | MockWrite("GET / HTTP/1.1\r\n" |
| 17898 | "Host: www.foo.com\r\n" |
| 17899 | "Connection: keep-alive\r\n" |
| 17900 | "Accept-Encoding: "), |
| 17901 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17902 | }; |
| 17903 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17904 | std::string response_code = "200 OK"; |
| 17905 | std::string extra; |
| 17906 | if (!location.empty()) { |
| 17907 | response_code = "301 Redirect\r\nLocation: "; |
| 17908 | response_code.append(location); |
| 17909 | } |
| 17910 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17911 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17912 | MockRead("HTTP/1.0 "), |
| 17913 | MockRead(response_code.data()), |
| 17914 | MockRead("\r\nContent-Encoding: "), |
| 17915 | MockRead(content_encoding.data()), |
| 17916 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17917 | MockRead(SYNCHRONOUS, OK), |
| 17918 | }; |
| 17919 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17920 | arraysize(data_writes)); |
| 17921 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17922 | |
| 17923 | TestCompletionCallback callback; |
| 17924 | |
| 17925 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17926 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17927 | |
| 17928 | rv = callback.WaitForResult(); |
| 17929 | if (should_match) { |
| 17930 | EXPECT_THAT(rv, IsOk()); |
| 17931 | } else { |
| 17932 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17933 | } |
| 17934 | } |
| 17935 | |
| 17936 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17937 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17938 | } |
| 17939 | |
| 17940 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17941 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17942 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17943 | } |
| 17944 | |
| 17945 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17946 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17947 | "", false); |
| 17948 | } |
| 17949 | |
| 17950 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17951 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17952 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17953 | } |
| 17954 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17955 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17956 | ProxyConfig proxy_config; |
| 17957 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17958 | proxy_config.set_pac_mandatory(true); |
| 17959 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17960 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17961 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17962 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 17963 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17964 | |
| 17965 | HttpRequestInfo request; |
| 17966 | request.method = "GET"; |
| 17967 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17968 | request.traffic_annotation = |
| 17969 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17970 | |
| 17971 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17972 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17973 | |
| 17974 | TestCompletionCallback callback; |
| 17975 | |
| 17976 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17977 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17978 | EXPECT_THAT(callback.WaitForResult(), |
| 17979 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17980 | } |
| 17981 | |
| 17982 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17983 | ProxyConfig proxy_config; |
| 17984 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17985 | proxy_config.set_pac_mandatory(true); |
| 17986 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17987 | new MockAsyncProxyResolverFactory(false); |
| 17988 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17989 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17990 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17991 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17992 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17993 | HttpRequestInfo request; |
| 17994 | request.method = "GET"; |
| 17995 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17996 | request.traffic_annotation = |
| 17997 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17998 | |
| 17999 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18000 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18001 | |
| 18002 | TestCompletionCallback callback; |
| 18003 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18004 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18005 | |
| 18006 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18007 | ERR_FAILED, &resolver); |
| 18008 | EXPECT_THAT(callback.WaitForResult(), |
| 18009 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18010 | } |
| 18011 | |
| 18012 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18013 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18014 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18015 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18016 | session_deps_.enable_quic = false; |
| 18017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18018 | |
| 18019 | HttpRequestInfo request; |
| 18020 | request.method = "GET"; |
| 18021 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18022 | request.traffic_annotation = |
| 18023 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18024 | |
| 18025 | TestCompletionCallback callback; |
| 18026 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18027 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18028 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18029 | |
| 18030 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18031 | } |
| 18032 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 18033 | } // namespace net |